please help debug

K

Karen

i have the following code on an On Exit of a control. When I enter data in
the cusno control and tab off of it I get an error that reads "Run time
error '2001': You cancelled the previous operation."

Can anyone help figure out what it is that I'm doing wrong?

Thanks,
Karen
------------------


Dim varcustnumber As String
Dim varbillname As Variant

Dim varzeros As String
varzeros = "000000000000"

Dim varlen As Integer
varlen = 12 - Len([CUSTNO])

varcustnumber = Mid(varzeros, 1, varlen) & [CUSTNO]

varbillname = DLookup("[cus_name]", "dbo_arcusfil_SQL", "[cus_no] =
varcustnumber")


(when i pause the cursor over varcustnumber in the dlookup statement, the
value is shown as "000000000080", which is correct.)
 
S

SusanV

Hi Karen,

What is "[cus_no]" ? Is this a field in the table? You should be referencing
a control on the form, instead. SO if the control for the customer number
were a textbox named txtCustNo you would reference it in your code as
Me.txtCustNo.

However, it looks to me (although I may be missing something here) that you
are trying to modify the customer number from 80 to 000000000080, or 412 to
000000000412, is this correct? If so you can simply use the Format function
to accomplish this using the AfterUpdate event of the textbox:

Me.txtCustNo = Format (Me.txtCustNo,"000000000000")
 
G

Guest

The syntax is incorrect. When you are referencing a variable, the variable
needs to be outside the quotes:
varbillname = DLookup("[cus_name]", "dbo_arcusfil_SQL", "[cus_no] =
varcustnumber")
Corrected:
varbillname = DLookup("[cus_name]", "dbo_arcusfil_SQL", "[cus_no] = '" &
varcustnumber & "'")
 
K

Karen

[cus_no] is a field in the dbo_arcusfil_sql table. If I use '000000000080'
instead of varcustnumber in the dlookup statement, I don't get the error so
I question the change of that field to a control on the form. I actually
get the lookup to work if i replace varcustnumber with a valid customer
number from the dbo_arcusfil_sql table.



SusanV said:
Hi Karen,

What is "[cus_no]" ? Is this a field in the table? You should be referencing
a control on the form, instead. SO if the control for the customer number
were a textbox named txtCustNo you would reference it in your code as
Me.txtCustNo.

However, it looks to me (although I may be missing something here) that you
are trying to modify the customer number from 80 to 000000000080, or 412 to
000000000412, is this correct? If so you can simply use the Format function
to accomplish this using the AfterUpdate event of the textbox:

Me.txtCustNo = Format (Me.txtCustNo,"000000000000")
--
hth,
SusanV


Karen said:
i have the following code on an On Exit of a control. When I enter data in
the cusno control and tab off of it I get an error that reads "Run time
error '2001': You cancelled the previous operation."

Can anyone help figure out what it is that I'm doing wrong?

Thanks,
Karen
------------------


Dim varcustnumber As String
Dim varbillname As Variant

Dim varzeros As String
varzeros = "000000000000"

Dim varlen As Integer
varlen = 12 - Len([CUSTNO])

varcustnumber = Mid(varzeros, 1, varlen) & [CUSTNO]

varbillname = DLookup("[cus_name]", "dbo_arcusfil_SQL", "[cus_no] =
varcustnumber")


(when i pause the cursor over varcustnumber in the dlookup statement, the
value is shown as "000000000080", which is correct.)
 
K

Karen

thank you! That was the correction i needed. I hope i remember this for
the next time i have to do this.

Karen

Klatuu said:
The syntax is incorrect. When you are referencing a variable, the variable
needs to be outside the quotes:
varbillname = DLookup("[cus_name]", "dbo_arcusfil_SQL", "[cus_no] =
varcustnumber")
Corrected:
varbillname = DLookup("[cus_name]", "dbo_arcusfil_SQL", "[cus_no] = '" &
varcustnumber & "'")


Karen said:
i have the following code on an On Exit of a control. When I enter data in
the cusno control and tab off of it I get an error that reads "Run time
error '2001': You cancelled the previous operation."

Can anyone help figure out what it is that I'm doing wrong?

Thanks,
Karen
------------------


Dim varcustnumber As String
Dim varbillname As Variant

Dim varzeros As String
varzeros = "000000000000"

Dim varlen As Integer
varlen = 12 - Len([CUSTNO])

varcustnumber = Mid(varzeros, 1, varlen) & [CUSTNO]

varbillname = DLookup("[cus_name]", "dbo_arcusfil_SQL", "[cus_no] =
varcustnumber")


(when i pause the cursor over varcustnumber in the dlookup statement, the
value is shown as "000000000080", which is correct.)
 

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

Similar Threads

fields in dlookup not filling in 6
closing a form that uses a Dlookup 2
debug error 1
Please HELP!! 4
Need a Delete Button? 6
Help with Code Please 4
Code Help 3
Help with code (Importing files) 1

Top