data type mismatch in criteria expression in vba

Waffeltje

Registered User.
Local time
Today, 01:42
Joined
Aug 12, 2014
Messages
11
Hi,

I'm getting the error when I run this code

Code:
Private Sub cmbSelectVan_AfterUpdate()
Dim DHLDepAllowed As Variant
Dim FedExDepAllowed As Variant
DHLDepAllowed = DLookup("DHL_from", "Zones_World", "Country_ID = '" & cmbSelectVan & "'")
    If (DHLDepAllowed < 1) Then
        MsgBox "blabla"
        cmdSelectVan.SetFocus
        Exit Sub
    End If

The code has to look up whether the DHL_from value is 1 or nothing. The error is on the Country_ID field.
 
if country_id is numeric, you don't need the single quotes, just

"Country_ID = " & cmbSelectVan
 
When I remove the single quote I get a syntax error in string in query expression ("Country ID")
 
Code:
DHLDepAllowed = DLookup("DHL_from", "Zones_World", "Country_ID = '" & [COLOR="Red"]cmbSelectVan[/COLOR] & "'")
... is a combo box and I think it's not returning the column data you're hoping for.
 
Yes it's a combobox.

But I've removed the single quote in the combobox and it's working.

Code:
cmbSelectVan & ""

Thanks nevertheless.
 
I thought you said that didn't work in your previous post?
 
Initially I only changed it into "Country_ID = ". Later on I also removed the single quote in cmbSelectVan &"".

It was thanks to you though, so thank you.
 
I wasn't complaining, I was just making sure you did it correctly.

Good job!
 

Users who are viewing this thread

Back
Top Bottom