Help me read (understand) vba (1 Viewer)

chappy68

Registered User.
Local time
Today, 02:36
Joined
Aug 15, 2011
Messages
76
I have a seemingly simple issue. I have a field in a form that requires a unique value (It is set in the table properties as index (no duplicates)). When I click the button I should get an error message if there is duplicate info as it tries to save the record. I am not getting the error message I expect as I test the form. I have copied the code behind the button below.

I got help (from this forum) stating the line "On Error Resume Next" is creating the problem. As I tried to fix the problem, I determined I did not understand the flow of the coding. I didn't know why this line of code was creating my problem.

Can someone easily explain the flow of vba? I think I will better be able to fix my own code if I learn/understand the flow of what I am coding.

If explaining the code the flow of the code is not a quick thing, can you point me in the direction of something that will explain how.

Hope this makes sense.

I am using Access 2007 on Windows 7.


'------------------------------------------------------------
' butSaveNewOnNewClient_Click
'
'------------------------------------------------------------
Private Sub butSaveNewOnNewClient_Click()
On Error GoTo butSaveNewOnNewClient_Click_Err
On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , "", acNext
ClientName.SetFocus
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If

butSaveNewOnNewClient_Click_Exit:
Exit Sub
butSaveNewOnNewClient_Click_Err:
MsgBox Error$
Resume butSaveNewOnNewClient_Click_Exit
End Sub
 

MarkK

bit cruncher
Local time
Today, 02:36
Joined
Mar 17, 2004
Messages
8,178
This line of code ...
Code:
On Error Resume Next
... says, "when an error occurs ignore it and execute the next line."
If you feel that your code should raise an error and it doesn't, it is because of this line, which tells program execution to continue like nothing happened.
Is that clearer?
 

chappy68

Registered User.
Local time
Today, 02:36
Joined
Aug 15, 2011
Messages
76
This line of code ...
Code:
On Error Resume Next
... says, "when an error occurs ignore it and execute the next line."
If you feel that your code should raise an error and it doesn't, it is because of this line, which tells program execution to continue like nothing happened.
Is that clearer?

Thanks for your help. I am trying to learn to "read" the code instead of just copy and paste solutions. I want to understand what I am doing.
 

Users who are viewing this thread

Top Bottom