Access World Forums

Access World Forums (https://www.access-programmers.co.uk/forums/index.php)
-   Forms (https://www.access-programmers.co.uk/forums/forumdisplay.php?f=9)
-   -   Problem with button coding (https://www.access-programmers.co.uk/forums/showthread.php?t=214316)

chappy68 08-17-2011 11:13 PM

Problem with button coding
 
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 as it tries to save the record. I am not getting the error message and the focus is set on the field ClientName. I have copied the code behind the button below.

What am I missing?

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 08-18-2011 09:45 AM

Your last enabled error handler is this:
Code:

On Error Resume Next
This supresses all errors from being raised.


All times are GMT -8. The time now is 04:32 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World