Question : Run-time errors'2105' and '3021'

Good afternoon Everyone, Does anyone know how to resolve the problem of run-time errors '2105' and '3021'? I got  a go to previous  button and when it reaches the record after the first record, it gives me run-time error'2105'. By the way, I got he code below for my go to previous button. Thank you very much again for the help.

Private Sub Command182_Click()
On Error GoTo err_des

DoCmd.GoToRecord , , acPrevious

Exit_Command182_Click:
Exit Sub

err_des:
MsgBox "You are on the first record"
Resume Exit_Command182_Click


 And when for my go to next record button, when it goes to the record that is blank, it gives me an error '3021'(no current record) By the way, I got the code for the go to next button below

Private Sub Command183_Click()
On Error GoTo Err_Command183_Click


    DoCmd.GoToRecord , , acNext

Exit_Command183_Click:
    Exit Sub

Err_Command183_Click:
    MsgBox Err.Description
    Resume Exit_Command183_Click
   
End Sub

Answer : Run-time errors'2105' and '3021'

With the above code the 2105 error should not appear, you should see 'You are on the first record' instead. The 3021 error will appear.

The way to deal with this is to use error handlers properly or to disable the appropriate buttons when on the first or last record.

A good example on how to do this can be found here: http://www.lebans.com/recnavbuttons.htm
Random Solutions  
 
programming4us programming4us