dlookup function gives error, you cancelled the previous opertation

have a simple database of state names and 2char
 codes  

state is a text string          
   state = LTrim(Mid(address, (newpos1 + 1), newpos2 - newpos1))
                 Me.ManagerState = state ' post state
'now I want to get the  2 character code
                 stcode = DLookup("code", "tblstatecodes", "name = " & state)
                  Me.ManagerState = stcode ' post 2char code

problem is 1. does not work, dlookup gives error you cancelled the previous opertation


the problem is in the crtiteria statement
states.mdb
durickAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jerryb30Commented:
stcode = DLookup("code", "tblstatecodes", "name = '" & state & "'")
Assuming [state] and [name] are text fields
0
mbizupCommented:
You need to delimit text with quotes like this:


stcode = DLookup("code", "tblstatecodes", "name = '" & state & "'")
0
mbizupCommented:
Also, since Name is a reserved word, use square brackets around it:

stcode = DLookup("code", "tblstatecodes", "[name] = '" & state & "'")

Alternatively:


stcode = DLookup("code", "tblstatecodes", "[name] = " & chr(34) &  state & chr(34))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
...yeah, I hate that cryptic error though...
:-O
0
mbizupCommented:
durick,

You had two different people helping you here, and we had very similar comments.  The points wound up split between two of my comments, with me getting all of the points.  Did you intend to divide the points between me and Jerry?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.