VBA - Label not defined compile Error

toveyj

New Member
Joined
Jun 15, 2007
Messages
22
Hi

Not very experienced at this VBA lark so hoping someone out there can enlighten me.
I am trying to put a simple error trap into a procedure in Access VBA.

Here is the code:

Sub Tbay()

On Error GoTo Proc_Err

'update linked tables to latest Torbay month mdb file
'if correct database not found, abort run

PCT = "TORBAY CARE TRUST"

LinkTorbay ' this is another sub that I pass the global PCT variable to
If LinkCheck = False Then
Exit Sub
End If

DoCmd.SetWarnings False

'I've removed the code that does everything in this bit

PCT = ""
MsgBox "Processing completed", vbOKOnly

Proc_Error:
DoCmd.SetWarnings True
MsgBox "An error occurred. Please check and re-start processing", vbOKOnly
Exit Sub
End Sub

The actual code is a lot longer but I've cut it down to simplify and
illustrate the problem. The longer version works without the error trapping
statement but won't compile - with the same error as this shortened version.
My problem is with the 'On Error Goto Proc_Error' line as I get a
compile error (label not defined). What am i doing wrong?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I don't believe I didn't notice that!
I tried it with various different label names and couldn't get it working.
I can't believe I misspelled it each time i changed the lable but that
is teh only answer I can come up with. Thank you for taking time to point out
my obvious mistake!
 
Upvote 0
toveyj

Do yourself a big favour. Go to http://mztools.com and download the free utility
MzTools 3.0 for VB6 and VBA.

It can build the error routine automatically and consistently with 1 mouse click. It does many more things also.
You won't regret using this tool.

Also, you should use
Option Explicit at the top of your modules to ensure things are defined and spelled consistently.
 
Upvote 0

Forum statistics

Threads
1,215,407
Messages
6,124,723
Members
449,184
Latest member
COrmerod

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top