Multiple DLookup - Access 2002

dcobau

Registered User.
Local time
Tomorrow, 10:04
Joined
Mar 1, 2004
Messages
124
g'day,

I put a button on a form to add records but, before doing so, I want to check if a record with the same id numbers is already in the table. To do so I use the following code:

If (DLookup("[CompanyID]", "tblBranchAddress", "CompanyID = " & Me![CompanyID] And _
"ContactsID = " & Me![ContactID])) Then

MsgBox "The name of this contact has already been recorded."
Me.Undo

' Else

' DoCmd.OpenForm "frmBranchAddress"
' DoCmd.GoToRecord , , acNewRec
' Forms!frmBranchAddress!CompanyID = Me!CompanyID
' Forms!frmBranchAddress!ContactsID = Me!ContactID

' Forms!frmBranchAddress!BranchBld.SetFocus

End If

The form consists of tabbed pages being frmCompany (the main form) and frmContacts (the sub form). I get the error "Type mismatch".

Any ideas? thanks

Dave
 
dc,

Two problems here ...

1) the AND clause is different from what you thought
2) the DLookUp returns CompanyID or NULL (success/failure)

Code:
If (Not IsNull(DLookup("[CompanyID]", _
                       "tblBranchAddress", 
                       "CompanyID = " & Me![CompanyID] & " And  " & _
                       "ContactsID = " & Me![ContactID])) Then ...

Wayne
 
thank you both

Dave
 

Users who are viewing this thread

Back
Top Bottom