G
GLT
Hi,
I have the code below on a button click. The code itself works fine,
however I would like the specific error when a dulicate record is added, to
be displayed in a message box with an exclamation point.
Whenever I force this error, nothing happens. Can anyone advise what I am
doing incorrectly?
Any help is always greatly appreciated...
Cheers,
GLT.
Private Sub Command21_Click()
On Error GoTo Command21_Click_Err
Dim strSQL As String
DoCmd.SetWarnings False
strSQL = "INSERT INTO tblPermSrvcsIgnore " & _
"( Type, Server, [Service Name] )" & _
" SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type" & _
", IIf([FORMS]![frmAddPermNoMon]![Frame7]=2, 'ALL', " & _
"[FORMS]![frmAddPermNoMon]![fldSelServer]) AS Server" & _
", [FORMS]![frmAddPermNoMon]![fldSelService] AS [Service Name];"
DoCmd.RunSQL strSQL
Me![tblPermSrvcsIgnore SubForm].Requery
DoCmd.SetWarnings True
Command21_Click_Exit:
Exit Sub
Command21_Click_Err:
DoCmd.SetWarnings True
MsgBox "This record already exists..."
Resume Command21_Click_Exit
End Sub
I have the code below on a button click. The code itself works fine,
however I would like the specific error when a dulicate record is added, to
be displayed in a message box with an exclamation point.
Whenever I force this error, nothing happens. Can anyone advise what I am
doing incorrectly?
Any help is always greatly appreciated...
Cheers,
GLT.
Private Sub Command21_Click()
On Error GoTo Command21_Click_Err
Dim strSQL As String
DoCmd.SetWarnings False
strSQL = "INSERT INTO tblPermSrvcsIgnore " & _
"( Type, Server, [Service Name] )" & _
" SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type" & _
", IIf([FORMS]![frmAddPermNoMon]![Frame7]=2, 'ALL', " & _
"[FORMS]![frmAddPermNoMon]![fldSelServer]) AS Server" & _
", [FORMS]![frmAddPermNoMon]![fldSelService] AS [Service Name];"
DoCmd.RunSQL strSQL
Me![tblPermSrvcsIgnore SubForm].Requery
DoCmd.SetWarnings True
Command21_Click_Exit:
Exit Sub
Command21_Click_Err:
DoCmd.SetWarnings True
MsgBox "This record already exists..."
Resume Command21_Click_Exit
End Sub