A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Issue with Error Number from Command Buttons



 
 
Thread Tools Display Modes
  #1  
Old December 14th, 2006, 04:16 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 1
Default 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  
Old December 14th, 2006, 06:20 PM posted to microsoft.public.access.forms
missinglinq via AccessMonster.com
external usenet poster
 
Posts: 545
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.