runtime error 2001

  • Thread starter Thread starter bubbadahut
  • Start date Start date
B

bubbadahut

Please help me to understand what is happening here.


I am trying to convert some code I found on a web site to fit my
application.

I have a table named "tblUsers"

with the fields:
fldUserID - autonumber
fldUser - text
fldPsWd - text


I have a from named "frmLogon"

with a two txt fields named "cmbUser" and "txtPsWd"

the cmbUser field is a combo box which gets its value from the
tblUsers.fldUserID
the txtPsWd is a text box

here is the code triggered by a comand button on frmLogon:

If Me.txtPsWd.Value = DLookup("fldPsWd", "tblUsers", "fldUserID=" &
Me.cmbUser.Value) Then

LoggedUser = Me.cmbUser.Value


My problem is this:

As it stands, the code works just fine. However, what I want to do is
change the combo box "cmbUser" to a text field "txtUser" with the
following code:

If Me.txtPsWd.Value = DLookup("fldPsWd", "tblUsers", "fldUsers=" &
Me.txtUser.Value) Then

LoggedUser = Me.txtUser.Value


As far as I can tell, everything works just the same except, when it
comes time to execute this line of code I get a "runtime error 2001,
You cancled the previous operation."

I have looked all over everywhere and can't find an answer to this,
and I just don't understand why it works ok using a combo box but not
with a text field. All the values appear to be correct.

thanks for your help
greg
 
Hi Greg

Because fldUser is a text field, you need to compare it with a text string
enclosed in quote marks.

If Me.txtPsWd.Value = DLookup("fldPsWd", "tblUsers", _
"fldUser='" & Me.txtUser.Value & "'") Then

If your objective is to have the user enter a name instead of a number, you
might like to consider reverting to the combo box, but set the number of
columns to 2, and set ColumnWidths to 0 (which hides the first column).
(I'm assuming the RowSource of the combo is tblUsers).

Then the *value* of the combo box will still be fldUserID, but what is
*displayed* will be fldUser.

You could even dispense with the DLookup altogether if you make
ColumnCount=3 and ColumnWidths=0;;0 (hide the first and third column). Then
the password will be available directly from the combo box, but hidden from
view, and your code can be simplified to:

If Me.txtPsWd.Value = Me.cmbUser.Column(2) Then

Note that Column(2) is the third column, because the count starts from zero.
 
Thank You Graham,

I was thinking that it probably had something to do with quotation
marks, but I didn't know "how" to fix and what I tried didn't work.
Thanks again for the reply and for your other suggestions as well.
I'll give this a go. :)
 
Back
Top