Data type mismatch

G

Guest

I'm having trouble getting this code to work.
I get the following error "Data type mismatch in criteria
expression" I know the error is created during the
dlookup operation. The data type
for "OutsideCityLimitsTaxRate"
and "InsideCityLimitsTaxRate" is currency with a standard
format. The data type for "ZipCode" and "PostalCode" is
text.

Here is the code I have so far:

Private Sub Command69_Click()
On Error GoTo Err_Command69_Click
Dim strCriteria As String
Dim strField As String
Dim curTaxRate As Currency

Rem DoCmd.RunCommand acCmdSaveRecord

If chkInsideCityLimits Then
strField = "InsideCityLimitsTaxRate"
Else
strField = "OutsideCityLimitsTaxRate"
End If

strCriteria = "ZipCode=" & [PostalCode]

curTaxRate = DLookup(strField, "Table_Tax_Rate",
strCriteria)

[Sales Tax Rate] = curTaxRate

Me.Refresh
MsgBox "Tax Information was updated."

Exit_Command69_Click:
Exit Sub

Err_Command69_Click:
MsgBox Err.Description
Resume Exit_Command69_Click

End Sub

Thanks for you help and time

Jason Frazer
 
J

John Spencer (MVP)

You need quotation marks around the PostalCode in the strCriteria. Try

strCriteria = "ZipCode=" & Chr(34) & [PostalCode] & Chr(34)

OR use

strCriteria = "ZipCode='" & [PostalCode] & "'"

OR use

strCriteria = "ZipCode=""" & [PostalCode] & """"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top