Error code help please

uniboy

Registered User.
Local time
Today, 23:45
Joined
Feb 11, 2011
Messages
16
In my booking system I have buttons that move to the next, previous, first and last record. but wen i click next and when its the end of the record set, it says theres a problem.

can you help me write a peice of code for which an error message appears and then loops.

my current code is:

'This goes to the next record
Private Sub cmdNext_Click()
DoCmd.RunCommand acCmdRecordsGoToNext
End Sub


'This goes to the previous code
Private Sub cmdPrevious_Click()
DoCmd.RunCommand acCmdRecordsGoToPrevious
End Sub



I was thinking something like this might work but it didn't:


Call displayCurrentRecord
Else
MsgBox "End of record set - no more records "
rstFilmDetails.MoveLast
End If

Loop +1


appreciate it if you could help, thanks
 
In your other thread you had Error Handlers. It's either you supress the error in the error handler:
Code:
Private Sub cmdNext_Click()
On Error Resume Next

    DoCmd.RunCommand acCmdRecordsGoToNext

    Err.Clear
End Sub
If you really want to show a msgbox everytime a move is invalid then you do something like this:
Code:
Private Sub cmdNext_Click()
On Error GoTo Err_bNext_Click

    DoCmd.RunCommand acCmdRecordsGoToNext
    
Exit_bNext_Click:
    Exit Sub
    
Err_bNext_Click:
    If Err.Number = [COLOR=Red][B]123 [/B][/COLOR]Then
        MsgBox "You have reached the end!"
    Else
        MsgBox Err.Description
    End If
    Resume Exit_bNext_Click
    
End Sub
I changed the error handler you had in your other thread. Note however that the number 123 was just a random number. You need to replace it with the correct error number. If accmdrecordsgotonext is the only code you will use in that click event of the button, then you can change the IF line to this:
Code:
If Err.Number <> 0 Then

The other way is to use the Button Wizard and select go to next record or previous record. Look at the code and see how this is handled.
 
cheers mate, appreciate it :)
 

Users who are viewing this thread

Back
Top Bottom