Help Exiting vbYes/No Msgbox

  • Thread starter poucedeleon via AccessMonster.com
  • Start date
P

poucedeleon via AccessMonster.com

I add this to my form to catch duplicate entries. It catches the dupilcate
entries but if I click "No" to "Cancel" it doesn't do anything. I am stuck on
the record unless I click "Yes" Should there be another If Statement in the
code?

**************************** Code********************************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tlkpStaff", "StaffLastName = """ & Me!StaffLastName & """ And
StaffFirstName = """ & Me!StaffFirstName & """") > 0 Then
If MsgBox("There is already a staff member by this name in table. Do
you wish to add it anyway?", vbYesNo) = vbNo Then
Cancel = True
End If
End If
End Sub
 
B

Beetle

Try adding an Undo after the cancel.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tlkpStaff", "StaffLastName = """ & Me!StaffLastName & """ And
StaffFirstName = """ & Me!StaffFirstName & """") > 0 Then
If MsgBox("There is already a staff member by this name in table. Do
you wish to add it anyway?", vbYesNo) = vbNo Then
Cancel = True
Me.Undo
End If
End If
End Sub
 
P

poucedeleon via AccessMonster.com

Thanks Beetle, That fixed it.
Try adding an Undo after the cancel.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tlkpStaff", "StaffLastName = """ & Me!StaffLastName & """ And
StaffFirstName = """ & Me!StaffFirstName & """") > 0 Then
If MsgBox("There is already a staff member by this name in table. Do
you wish to add it anyway?", vbYesNo) = vbNo Then
Cancel = True
Me.Undo
End If
End If
End Sub
I add this to my form to catch duplicate entries. It catches the dupilcate
entries but if I click "No" to "Cancel" it doesn't do anything. I am stuck on
[quoted text clipped - 11 lines]
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top