I am trying to develop a Dlookup function that uses two criteria to lookup the value I am not having any luck. The two values are city and state to lookup a zipcode. I have a table called tblZipCode that has columns called City, State and ZipCode. The form is called frmJobInformation. The textboxes on the form are called txtCompanyCity, txtCompanyState and txtCompanyZipCode.
I get a compile error of too many arguments. Any help is appreciated.
I get a compile error of too many arguments. Any help is appreciated.
Code:
Private Sub lstCompanyState_Exit(Cancel As Integer)
Dim X, Y As String
On Error GoTo ERR_CompanyState
Forms![frmJobInformation]![txtCompanyZipCode] = DLookup("[txtCompanyCity]" And "[txtCompanyState]", "[CompanyZipCode]", "tblZipCode", "[txtCompanyZipCode] = Forms![frmJobInformation]!CompanyZipCode")
Exit Sub
ERR_CompanyState:
MsgBox "No Data"
Exit Sub
End Sub