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
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