If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Issue with Error Number from Command Buttons
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 |
#2
|
|||
|
|||
Issue with Error Number from Command Buttons
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 http://www.accessmonster.com/Uwe/For...forms/200612/1 |
Thread Tools | |
Display Modes | |
|
|