Jeremy
Jeremy

Reputation: 43

Access VBA “Compile Error: Label not defined”

One of my associates has inadvertently messed up an old Access export script and we are now receiving the "Label not defined" error and I am not anywhere close to an Access guru, any help would be nice.

Function Macro2()
On Error GoTo Macro2_Err

    DoCmd.TransferText acExportDelim, "golfexport", "ctcexport", "P:\transferdata\golfexport05052017"
    Exit Function

Macro2_Err:
    MsgBox Error$
    Resume Macro2_Exit

End Function

The error is highlighting the top row in yellow and the "Resume Macro2_Exit" line.

Anybody have an idea as it was most likely a fat finger to backspace that killed something.

thanks

Upvotes: 0

Views: 4440

Answers (1)

Mathieu Guindon
Mathieu Guindon

Reputation: 71177

Resume [Label]

That instruction requires a line label to exist, so that execution can resume there. If the label isn't defined, there's nowhere to jump to, and the code can't compile.

If that's all there is to the procedure, you can just remove the Resume instruction and call it a day. If there's code between DoCmd and Exit Function, you can define the label there:

Macro2_Exit:
    Exit Function
Macro2_Err:
    MsgBox Err.Description
    Resume Macro2_Exit

Note the use of Err.Description instead of the dinosaurian Error$ string. Just a suggestion though.

Upvotes: 1

Related Questions