Run-time error '2001'

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
Back
Top