DLookup problem.

L

Linda

I'm getting a type mismatch error when trying to run the
following:

lngpropid = DLookup
("[PropID]", "tblTenantsinSplitBillArchive", "[PropID]
= " & cbokeynr.Column(1) And [DateInvoice] = "#" &
dteinvoice & "#")

Does anyone see what the problem is? Thanks!
 
A

Allen Browne

Suggestions:

1. The 3rd argument is malformed. Try:
Dim strWhere As String
strWhere = "[PropID] = " & cbokeynr.Column(1) & " AND [DateInvoice] = #" &
dteinvoice & "#"
lngpropid = DLookup("[PropID]", "tblTenantsinSplitBillArchive", strWhere)

2. Assuming "cbokeynr" is a combo, check its RowSource. What is the data
type of the field in the 2nd column (because the first column is column 0)?
If it is a Text field, and PropID is a Number, you have a mismatch. If they
are both Text fields, you need extra quotes, i.e.:
strWhere = "[PropID] = """ & cbokeynr.Column(1) & """ AND [DateInvoice] = #"
& dteinvoice & "#"

3. DLookup() could return a Null if the result is not found. If "lngpropid"
is a Long, that won't work.
 
Top