Syntax error using dlookup

  • Thread starter Thread starter Hugh self taught
  • Start date Start date
H

Hugh self taught

Hi All,

I have the following piece of code

ChkProv = DLookup("[Province_Cde]", "Provinces", "[Province_Cde]= ' " &
Left(Nat_Reg, 2))

which I want to use as part of validating that the 1st 2 left chrs of
Nat_Reg correspond with a record in field Province_Cde

However it gives me the following error when executed

Syntax error in string in query expression '[Province_Cde]='GU'

GU is valid in the record I was trying to add as a test & it exists in the
table Provinces.Province_Cde

Any suggestions on what to try to correct this?

Hugh
 
Missing a close quote mark and have a leading space in the third argument
before getting the two characters from Nat_Reg.

ChkProv = DLookup("Province_Cde", "Provinces", "Province_Cde= '" &
Left(Nat_Reg, 2) & "'")



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Hugh said:
ChkProv = DLookup("[Province_Cde]", "Provinces", "[Province_Cde]= ' " &
Left(Nat_Reg, 2))

which I want to use as part of validating that the 1st 2 left chrs of
Nat_Reg correspond with a record in field Province_Cde

However it gives me the following error when executed

Syntax error in string in query expression '[Province_Cde]='GU'

GU is valid in the record I was trying to add as a test & it exists in the
table Provinces.Province_Cde

You forgot the closing '

ChkProv = DLookup("[Province_Cde]", "Provinces",
"[Province_Cde]= '" & Left(Nat_Reg, 2) & "' ")
 
Hi John, Marshall & Daniel

Many thanks for the help. Although my knowledge is growing I'm not
proficient at find my intricate errors yet. Works like a charm now

Hugh

John Spencer said:
Missing a close quote mark and have a leading space in the third argument
before getting the two characters from Nat_Reg.

ChkProv = DLookup("Province_Cde", "Provinces", "Province_Cde= '" &
Left(Nat_Reg, 2) & "'")



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hi All,

I have the following piece of code

ChkProv = DLookup("[Province_Cde]", "Provinces", "[Province_Cde]= ' " &
Left(Nat_Reg, 2))

which I want to use as part of validating that the 1st 2 left chrs of
Nat_Reg correspond with a record in field Province_Cde

However it gives me the following error when executed

Syntax error in string in query expression '[Province_Cde]='GU'

GU is valid in the record I was trying to add as a test & it exists in the
table Provinces.Province_Cde

Any suggestions on what to try to correct this?

Hugh
.
 
Back
Top