Run-time error '2001'

G

Guest

Hi
I am trying to get a dlookup statement to return a value and get the error
message 'Runtime error 2001 you canceled the previous operation. Iknow the
syntax is correct because it works against a tbale where I look up the
county. It does not work against the companies table. I have tried it in the
immediate window and this is the error message I get. What I cant understand
is how it works on one line but not the next.
Code extraxt:

strCounty = DLookup("[County]", "[tblCounties]", "[ID] =" & Me.cboCounty)

If Me.cboCompanyName <> 0 Then
strCompany = DLookup("[Company Name]", "[tblCompanies]",
"[CompanyID] =" & _
Me.cboCompanyName)
End If
 
N

Nikos Yannacopoulos

Paul,

Am I right to assume the ID field in tblCountries is type Text? In that
case, you need to take that into account in the syntax, i.e. your expression
must include (single) quotes around the combo reference:

strCounty = DLookup("[County]", "[tblCounties]", "[ID] = '" & Me.cboCounty &
"'")

HTH,
Nikos
 
G

Guest

Hi Nikos

No the County ID field is autonumber as is the CompanyID field. The county
DLookup works fine its the company one that produces the runtime error, hence
my confusion.

Paul

Nikos Yannacopoulos said:
Paul,

Am I right to assume the ID field in tblCountries is type Text? In that
case, you need to take that into account in the syntax, i.e. your expression
must include (single) quotes around the combo reference:

strCounty = DLookup("[County]", "[tblCounties]", "[ID] = '" & Me.cboCounty &
"'")

HTH,
Nikos

PaulCram said:
Hi
I am trying to get a dlookup statement to return a value and get the error
message 'Runtime error 2001 you canceled the previous operation. Iknow the
syntax is correct because it works against a tbale where I look up the
county. It does not work against the companies table. I have tried it in the
immediate window and this is the error message I get. What I cant understand
is how it works on one line but not the next.
Code extraxt:

strCounty = DLookup("[County]", "[tblCounties]", "[ID] =" & Me.cboCounty)

If Me.cboCompanyName <> 0 Then
strCompany = DLookup("[Company Name]", "[tblCompanies]",
"[CompanyID] =" & _
Me.cboCompanyName)
End If
 

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