Issue with Error Number from Command Buttons

O

ofarah

I have created command buttons in my form and I have customized error
messages. The problem is, I am getting the same error number for
different types of error from the command buttons. I have some required
fields in my form. For example, I have a Previous command button. I am
getting the same error when I click on Previous on the first record and
when I click Previous while adding a new record but haven't filled the
required fields.
I was hoping that I will get different errors so that I can see if the
error message should be "This is the first record" or "Please fill the
required fields". I am getting error number: 2105 in both cases.
Following is the code that I am using to check the error number:

Private Sub Previous_Click()
On Error GoTo Err_Previous_Click

DoCmd.GoToRecord , , acPrevious

Exit_Previous_Click:
Exit Sub

Err_Previous_Click:

'Display a standard error message
MsgBox "Error #: " & Err.Number & " " & Err.Description
Debug.Print Err.Number

End Sub

Am I am doing something wrong here? Any help is appreciated. Thank you
 
M

missinglinq via AccessMonster.com

You get the same error number because the same error is occurring "You can't
go to specified record"
which is true in either case. You can keep Access from displaying it's
warning by placing

DoCmd.SetWarnings False

at the beginning of your proceedure then

DoCmd.SetWarnings True

at the end to turn the native warnings back on (be sure and do this)

You'll need to replace

Err_Previous_Click:

'Display a standard error message
MsgBox "Error #: " & Err.Number & " " & Err.Description
Debug.Print Err.Number

with your own message boxes. I don't have access to Access right now and
can't test this, but you need something similar to:

Err_Previous_Click:

If Me.NewRecord Then
Msgbox "You must fill in all fields first"
Else
Msgbox "This is the first Record, Idiot!"
End If

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top