Results 1 to 7 of 7
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Subform Top Record Always in View (2003)

    In the startup form of the attached mdb, I change the day that filters the records displayed in the subform using the cmdNext and cmdPrev buttons. Whenever the user moves to another day, the following code in the buttons' click event makes sure the record at the top is always displayed
    Me.Form!Mag.SetFocus
    DoCmd.GoToRecord , , acFirst
    but how can I avoid the error message such code throws if you try to move to a day that has no records?
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Subform Top Record Always in View (2003)

    If you would like help, please stop attaching databases that are almost impossible to use:
    - Don't set a startup form.
    - Don't include unnecessary references that will almost certainly be missing on other PCs causing code to fail.
    - Don't use popup forms.
    - Don't use code that quits Access as soon as you close the form.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform Top Record Always in View (2003)

    Sorry Hans <img src=/S/blush.gif border=0 alt=blush width=15 height=15>, attached you find a version with all your requests carried out <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Attached Files Attached Files

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform Top Record Always in View (2003)

    It's ok Hans, I've solved it using the following code in the click event for the cmdNext and cmdPrev buttons <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    <pre> Set cnn = CurrentProject.Connection
    rst.Open "mag", cnn, adOpenKeyset, adLockOptimistic
    rst.MoveFirst
    rst.Find ("Giorno=" & Cdata)
    If rst.EOF Then
    Set cnn = Nothing
    Set rst = Nothing
    Exit Sub
    End If
    Set cnn = Nothing
    Set rst = Nothing
    Mag.SetFocus
    DoCmd.GoToRecord , , acFirst
    Testo148.SetFocus
    </pre>


  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform Top Record Always in View (2003)

    Since, on the FDezzo form, I'm also using a calendar to move from day to day, I've tried to use the same code in Public Sub cmdSave_Click() for the frmCalendarOCX form that the Comando136 button on the FDezzo form brings up but this time, when I select a day on the calendar(say, 16 Jan 2009) and click the Save button, I get an error at the line
    Forms!FDezzo!Mag.Form.Testo148.SetFocus
    saying "Application-defined or object-defined error".
    Why does this line give such error?
    Attached Files Attached Files

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Subform Top Record Always in View (2003)

    Because there is no control named Testo148 <img src=/S/yikes.gif border=0 alt=yikes width=15 height=15> on the Mag subform. It is a control on FDezzo itself.

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform Top Record Always in View (2003)

    <img src=/S/doh.gif border=0 alt=doh width=15 height=15> <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>Hans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •