I'd suggest using Boolean (Yes/No) PrimaryContact column in the Contacts
table rather than a numeric column. If you want to be able to edit the
primary contact record on page 1 of the tab control you can have a subform
with a RecordSource of:
SELECT *
FROM Contacts
WHERE PrimaryContact;
This subform, like that for the full contact list on the other page of the
tab control, would be linked to the parent form on CustomerID, and both could
include a check box bound to the PrimaryContact column. As it would be
necessary to uncheck the current primary contact (or delete the record)
before making another contact the primary contact, you could put some
validation code in the full contact list subform's BeforeUpdate event
procedure to prevent two contacts being made 'primary', e.g.
Const conMESSAGE = "Another contact is already designated " & _
"Primary Contact for this customer. "You must remove that " & _
" designation, or delete that contact record before designating " & _
" a new Primary Contact."
Dim strCriteria As String
strCriteria = _
"CustomerID = " & Me.CustomerID & _
" And ContactID <> " & Me.ContactID & _
" And PrimaryContact")
If Me.PrimaryContact Then
If Not IsNull(DLookup("ContactID", "Contacts", strCriteria)) Then
MsgBox conMESSAGE, vbExclamation, "Warning"
Cancel = True
End If
End If
In the AfterUpdate event procedure of the full contact list subform you
would need to requery the primary contact subform so it shows the new primary
contact:
Me.Parent.sfrPrimaryContact.Requery
where sfrPrimaryContact is the name of the subform control on page 1 of the
tab (i.e. the control which houses the subform) Similarly in the primary
contact subform you would requery itself in its AfterUpdate event procedure:
Me.Requery
If you don't want to be able to edit the primary contact record on the first
page of the tab but only in the full contact list you could use an unbound
text box rather than a subform, with a ControlSource property such as:
=DLookup("Firstname & "" "" & LastName","Contacts","PrimaryContact And
CustomerID = " & [CustomerID])
The validation code in the full contact list subform's module would still be
needed, however, but obviously you would not now need to requery the first
subform.
Ken Sheridan
Stafford, England