R
RipperT
The following code works fine until the user clicks No in the msgBox. When
No is clicked, the Access error message about duplicate values fires before
the Undo command. I would like it to just return the field to the previous
value if the user clicks No. I tried the code in the before update event,
but that didn't solve the problem. Any help will be appreciated.
Private Sub InmateId After_Update()
Dim strSQL as String
If Not IsNull(DLookup("InmateId", "tblLockAllocations", "[InmateId] = '" &
Me.InmateId & "'")) Then
If MsgBox("This value already exists in the table" & vbNewLine _
& "Click yes to move the value to this record. Otherwise click No.",
vbInformation + vbYesNo, "Change Lock") = vbYes Then
strSQL = "UPDATE tblLockAllocations SET InmateId = NULL _
& " WHERE InmateId = '" & Me.InmateId & "';"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
MsgBox "Lock Change Successful"
Else: Me.InmateId.Undo
Me.InmateId.SetFocus
End if
Else: DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Lock Change Successful."
Me.InmateId.SetFocus
End if
End Sub
No is clicked, the Access error message about duplicate values fires before
the Undo command. I would like it to just return the field to the previous
value if the user clicks No. I tried the code in the before update event,
but that didn't solve the problem. Any help will be appreciated.
Private Sub InmateId After_Update()
Dim strSQL as String
If Not IsNull(DLookup("InmateId", "tblLockAllocations", "[InmateId] = '" &
Me.InmateId & "'")) Then
If MsgBox("This value already exists in the table" & vbNewLine _
& "Click yes to move the value to this record. Otherwise click No.",
vbInformation + vbYesNo, "Change Lock") = vbYes Then
strSQL = "UPDATE tblLockAllocations SET InmateId = NULL _
& " WHERE InmateId = '" & Me.InmateId & "';"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
MsgBox "Lock Change Successful"
Else: Me.InmateId.Undo
Me.InmateId.SetFocus
End if
Else: DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Lock Change Successful."
Me.InmateId.SetFocus
End if
End Sub