• Subform Top Record Always in View (2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Subform Top Record Always in View (2003)

    Author
    Topic
    #457404

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #1146784

      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.

      • #1146785

        Sorry Hans blush, attached you find a version with all your requests carried out smile

      • #1146787

        It’s ok Hans, I’ve solved it using the following code in the click event for the cmdNext and cmdPrev buttons smile

            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
        
      • #1146812

        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?

    Viewing 0 reply threads
    Reply To: Subform Top Record Always in View (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: