Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dependent fields 1

Status
Not open for further replies.
May 25, 2004
7
US
Is it possible to make one field dependent on another? For instance, I am building a basic contact database and would like to require that either a last name be entered or an organization. If there isn't one or the other or both, I would like an error message to popup and require one of the fields be filled.

Thanks in advance.
 
Something like this should do the trick

Code:
Private Sub MyForm_BeforeUpdate(Cancel as Integer)
    If (IsNull(Me.LastName) OR Me.LastName = "") AND (IsNull(Me.Organization) OR Me.Organization = "") Then
        MsgBox "A Last Name or Organization Name is required",VBOkOnly, "Missing Data"
        Cancel = true
        Me.LastName.SetFocus
    End If
End Sub
Note: I wrote this on the fly, so the syntax may not be exactly correct.


HTH
Lightning
 
wintergreen

Well give Lighting a star is (s)he made your day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top