Trouble with DLookup

G

Guest

I can't get my form to show me the DLookup value. I have an unbound form
with a combo box that looks up the UserNames from table Users. My DLookup is
supposed to show me the value of the [Password] where the [UserName] is the
same as the txtUserName from the form. (UserName is a Lookup value based on
the employee ID, so is actually numerical. So, no enclosing quotes are
necessary.)
Here is the control source property for the Dlookup text box:
=DLookUp("[Password]","Users","[UserName] =" & [Form]![txtUserName])
When a selection is made in the combobox (UserName) the DLookup value is
either blank or there is an error stating that there is a syntax error. I
can't find it. I need a new set of eyes... Can anyone help?
 
G

Guest

To refer to a text box in the form you should use

[Forms]![FormName]![txtUserName]
=DLookUp("[Password]","Users","[UserName] =" &
[Forms]![FormName]![txtUserName])

Or, if its in the form use
Me.txtUserName
=DLookUp("[Password]","Users","[UserName] =" & Me.txtUserName)


Or, if the dlookup writen in the control source of the text box you can use
=DLookUp("[Password]","Users","[UserName] =" & [txtUserName])
 
G

Guest

Well, poop. That didn't seem to solve my problem. The DLookup text box is
still blank. Perhaps I am making bad assumptions. I want the DLookup to
lookup the [Password] or [UserName] in the "Users" table when the selection
in the combobox (txtUserName) matches the record [UserName] in the table.
They should be numerical values, since they are based on the EmployeeID
number from the Employees table. The form it is located on is called
frmEnterPassword and is unbound. The combobox (txtUserName) uses this as the
row source:
SELECT Employees.[Employee Name], Users.Password FROM Employees INNER JOIN
Users ON Employees.ID = Users.UserName;
That makes me think that perhaps DLookup is looking for a matching
EmployeeID in the Users table, but isn't finding one.
--
Why are you asking me? I dont know what Im doing!

Jaybird


Ofer Cohen said:
To refer to a text box in the form you should use

[Forms]![FormName]![txtUserName]
=DLookUp("[Password]","Users","[UserName] =" &
[Forms]![FormName]![txtUserName])

Or, if its in the form use
Me.txtUserName
=DLookUp("[Password]","Users","[UserName] =" & Me.txtUserName)


Or, if the dlookup writen in the control source of the text box you can use
=DLookUp("[Password]","Users","[UserName] =" & [txtUserName])


--
Good Luck
BS"D


Jaybird said:
I can't get my form to show me the DLookup value. I have an unbound form
with a combo box that looks up the UserNames from table Users. My DLookup is
supposed to show me the value of the [Password] where the [UserName] is the
same as the txtUserName from the form. (UserName is a Lookup value based on
the employee ID, so is actually numerical. So, no enclosing quotes are
necessary.)
Here is the control source property for the Dlookup text box:
=DLookUp("[Password]","Users","[UserName] =" & [Form]![txtUserName])
When a selection is made in the combobox (UserName) the DLookup value is
either blank or there is an error stating that there is a syntax error. I
can't find it. I need a new set of eyes... Can anyone help?
 
G

Guest

In that case you don't need to use a dlookup, you can refer to the password
in the combo

=[ComboName].Column(1)

The column number start with 0.

--
Good Luck
BS"D


Jaybird said:
Well, poop. That didn't seem to solve my problem. The DLookup text box is
still blank. Perhaps I am making bad assumptions. I want the DLookup to
lookup the [Password] or [UserName] in the "Users" table when the selection
in the combobox (txtUserName) matches the record [UserName] in the table.
They should be numerical values, since they are based on the EmployeeID
number from the Employees table. The form it is located on is called
frmEnterPassword and is unbound. The combobox (txtUserName) uses this as the
row source:
SELECT Employees.[Employee Name], Users.Password FROM Employees INNER JOIN
Users ON Employees.ID = Users.UserName;
That makes me think that perhaps DLookup is looking for a matching
EmployeeID in the Users table, but isn't finding one.
--
Why are you asking me? I dont know what Im doing!

Jaybird


Ofer Cohen said:
To refer to a text box in the form you should use

[Forms]![FormName]![txtUserName]
=DLookUp("[Password]","Users","[UserName] =" &
[Forms]![FormName]![txtUserName])

Or, if its in the form use
Me.txtUserName
=DLookUp("[Password]","Users","[UserName] =" & Me.txtUserName)


Or, if the dlookup writen in the control source of the text box you can use
=DLookUp("[Password]","Users","[UserName] =" & [txtUserName])


--
Good Luck
BS"D


Jaybird said:
I can't get my form to show me the DLookup value. I have an unbound form
with a combo box that looks up the UserNames from table Users. My DLookup is
supposed to show me the value of the [Password] where the [UserName] is the
same as the txtUserName from the form. (UserName is a Lookup value based on
the employee ID, so is actually numerical. So, no enclosing quotes are
necessary.)
Here is the control source property for the Dlookup text box:
=DLookUp("[Password]","Users","[UserName] =" & [Form]![txtUserName])
When a selection is made in the combobox (UserName) the DLookup value is
either blank or there is an error stating that there is a syntax error. I
can't find it. I need a new set of eyes... Can anyone help?
 

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


Top