G
Guest
I have a Continuous form for entering account mnemonics. Each mnemonic must
be unique. If someone dups a mnemonic, the code identifies this and displays
a message, but the DoCmd.Undo won't work. I'm trying to find away to delete
the duplicated mnemonic or otherwise undo what triggered the message. FYI:
the mnemonic field is set as the primary key field. Code follows:
Private Sub txtMnemonic_BeforeUpdate(Cancel As Integer)
Dim strMnemonic As String
Dim vCompany As Variant
On Error Resume Next
strMnemonic = Me.txtMnemonic.Text
If Not IsNull(strMnemonic) Then
vCompany = DLookup("[LegalName]", "tbl_Mnemonics", "[Mnemonic] = " &
Chr$(34) & strMnemonic & Chr$(34))
If Not IsNull(vCompany) Then
MsgBox "This mnemonic already exists in association with " &
vCompany & ".", vbExclamation, "Entry Failure"
DoCmd.RunCommand acCmdUndo
DoCmd.RunCommand acCmdUndo
Else
'do nothing
End If
End If
End Sub
be unique. If someone dups a mnemonic, the code identifies this and displays
a message, but the DoCmd.Undo won't work. I'm trying to find away to delete
the duplicated mnemonic or otherwise undo what triggered the message. FYI:
the mnemonic field is set as the primary key field. Code follows:
Private Sub txtMnemonic_BeforeUpdate(Cancel As Integer)
Dim strMnemonic As String
Dim vCompany As Variant
On Error Resume Next
strMnemonic = Me.txtMnemonic.Text
If Not IsNull(strMnemonic) Then
vCompany = DLookup("[LegalName]", "tbl_Mnemonics", "[Mnemonic] = " &
Chr$(34) & strMnemonic & Chr$(34))
If Not IsNull(vCompany) Then
MsgBox "This mnemonic already exists in association with " &
vCompany & ".", vbExclamation, "Entry Failure"
DoCmd.RunCommand acCmdUndo
DoCmd.RunCommand acCmdUndo
Else
'do nothing
End If
End If
End Sub