Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is a Run-Time code 0

Status
Not open for further replies.

theundergod

IS-IT--Management
Feb 4, 2005
30
US
Here's my dilema. I am new to VBA and am currently doing some simple VBA instead of macros in order to become more familiar. I have a button that creates a new record and have this code as the event:

DoCmd.GoToRecord , , acNewRec

For some reason the code won't work and it spits out a run-time error "2105" UNLESS I make a button, use the wizard to set it up, and then copy the code from that button to my button. The code is the same with the exception of some error handling. This is the code it produces:

On Error GoTo Err_Command22_Click


DoCmd.GoToRecord , , acNewRec

Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

Now, if I take everything out except for the "DoCmd.GoToRecord , , acNewRec" and copy and paste it, it still works with my button. There's absolutely no difference between that code and mine. Or am I completely missing something? I have found through troubleshooting that the working code still spits out a run-time error "0". Is an error "0" a standard error that VBA uses when creating a new record?

Any information would be gladly accepted. Thanks.

-Jon
 
You are trapping a non existant error, error 0.

The code normally runs like this....

DoCmd.GoToRecord , , acNewRec
Exit Sub

But if it hits an error, the instruction

On Error GoTo Err_Command22_Click means it runs this.....

DoCmd.GoToRecord , , acNewRec
MsgBox Err.Description
Resume Exit_Command22_Click (redirect to the exit point)
Exit Sub

Now the exit sub stops it entering the error handler

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

Unless an error occurs

So.....

On Error GoTo Err_Command22_Click


DoCmd.GoToRecord , , acNewRec

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

will run

DoCmd.GoToRecord , , acNewRec
MsgBox Err.Description

no matter if an error occurs or not. If no error occurs, the error encountered is error 0.




 
Ah I see. Thank you so much for clearing that up. That was bugging me to no end.

Now any idea why it would only work if I copied the code instead of typing it myself?

-Jon
 
HaHa! I would love to think that as well but I have done it more than once to make sure that wasn't the case. At least it works now, these computers at work are having a hard time right now because of network infrastructure changes. Who knows, they've done extremely strange things before. Maybe it was just a glitch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top