Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Next record command button not working

I have a form that is loading by [Project].  Then I have a "Next Record" command button in the footer of the form.  This button works fine to go from one record to the next record.  But then I also have a combo-box on the form that allows the user to "Find" a record.  The afterupdate event takes them to the desired record just fine.

But here is the problem..   After the afterupdate event has taken the user to the desired record, the "Next Record" button no longer works.  Instead, they are taken to a blank record.

Here is my next record VBA code:

DoCmd.GoToRecord , "", acNext

????
Avatar of SteveL13
SteveL13
Flag of United States of America image

ASKER

I just realized that after the afterupdate event fires, the form is filtered.  Is there a way to avoid this when the "Next Record' button is clicked?
Avatar of John Tsioumpris
Me.Filter =""
Me.FilterOn = false

Open in new window

Is not working.  Is taking me back to the first record.

Here is my code so far:

Private Sub cmdNextRecord_Click()
On Error GoTo Err_cmdNextRecord_Click

    On Error Resume Next
   
    Me.Filter = ""
    Me.FilterOn = False
   
    DoCmd.GoToRecord , "", acNext
   
    Me.cmdFocus.SetFocus
   
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
            End If

Exit_cmdNextRecord_Click:
    Exit Sub

Err_cmdNextRecord_Click:
    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
    Resume Exit_cmdNextRecord_Click

End Sub
Actually it is taking me back to the 1st record + 1
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Changed to:

    Dim ID  As String
   
    ID = Me!cboProject.Value
    Me.FilterOn = False
   
    Me!cboProject.SetFocus
    DoCmd.FindRecord ID
    DoCmd.GoToRecord , , acNext
    Me.cmdFocus.SetFocus

Thank you.
You are welcome!