Compile Error: Label not defined

G

Guest

I keep getting "Compile Error: Label not defined" for this function with "On
Error GoTo HandleError" highlighted. But I cannot find any syntax problems.
I'm probably missing something obvious...

Private Function saveRow() As Boolean
On Error GoTo HandleError
If Form.Dirty Then
Form.Dirty = False
End If

Exit_Save:
saveRow = True
End Function

HandleError:
MsgBox "The data you have entered does not meet the requirements for
this form. Please finish entering the data, or press ESC to undo your
entry.", vbExclamation
saveRow = False
End Function
 
G

Guest

Hey Heather, a couple of things:

Instead of End Function, try Exit Function and add a resume statement after
the error message. I also move the saveRow = True within the if statement.
Let me know if this works for you:

Private Function saveRow() As Boolean
On Error GoTo HandleError
If Form.Dirty Then
Form.Dirty = False
saveRow = True
End If

Exit_Save:
Exit Function

HandleError:
MsgBox "The data you have entered does not meet the requirements for
this form. Please finish entering the data, or press ESC to undo your
entry.", vbExclamation
saveRow = False
Resume Exit_Save

End Function
 
G

Guest

Hi, Heather.

You have "End Function" in the middle of your function, instead of "Exit
Function" to terminate the function early. For example:

Exit_Save:
saveRow = True
Exit Function

HandleError:

MsgBox "The data you have entered does not meet the requirements for
this form. Please finish entering the data, or press ESC to undo your
entry.", vbExclamation
saveRow = False
End Function

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top