Hi, all!
The code below been working perfectly -- I added tons of contacts last week, and the messages worked exactly as they should.
Today, I am getting the MsgBox regardless of my choice in the Primary Contact field.
I have made changes to the database, but none that would affect this -- nevertheless, I went back and confirmed all the field names.
Can you think of any reason it would not work now?
Here is the code:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.PrimaryContact = "Yes" Then
If Not IsNull(DLookup("PrimaryContact", "ContactsT", "PrimaryContact = ""Yes"" AND ContactOrg=""" & Me.ContactOrg & """")) Then
MsgBox "This organization already has a primary contact. There can be only one primary contact at an organization. Please edit the other contact before designating this person as the primary contact."
Cancel = True
End If
Else
If DCount("ID", "ContactsT", "ContactOrg=""" & Me.ContactOrg & """") <= 1 Then
MsgBox "Each organization must have a primary contact. This is the only contact for this organziation, so you must choose Yes."
Cancel = True
End If
End If
End Sub
I double-checked the field names, and it's all good -- I hadn't changed any, but I checked nonetheless!
I am perplexed!
I am so close to being done ... and now ... an ugly wrinkle!
Thank you for any thoughts!
--ak