Running A Select Query When I open a form.

  • Thread starter nouveauricheinvestments
  • Start date
N

nouveauricheinvestments

Hi,

I have a select query that is based on the value of a textbox on my
form. I have another textbox on my form that I want to = the value of
the ID of the query. The query will always return only 1 record. How
do I do this? This is what I have right now, and it is giving me the
following error: #Name?

This is in the textbox that I have set to = the ID field of my query:

=[FindEmployeeID]![ID]

My query is a select query with the following criteria:

[Forms]![EnterNewObservation]![ThisUser]

ThisUser is a textbox on my current form as well.

What should I do differently?
 
B

Brian

=DLookup("[ID]","[FindEmployeeID]")

However, you could also combine these into one line and not need the query.

=DLookup("[ID]","[FindEmployeeID]","[User] = '" &
[Forms]![EnterNewObservation]![ThisUser] & "'")

Furthermore, since they both come from the same table, it would simplify
things to use one field instead of two. Bind your User combo box to ID, make
it two columns wide, bind it to the first column, and hide the first column.
This way, it would store the ID but display the user name.
 
N

nouveauricheinvestments

=DLookup("[ID]","[FindEmployeeID]")

However, you could also combine these into one line and not need the query.

=DLookup("[ID]","[FindEmployeeID]","[User] = '" &
[Forms]![EnterNewObservation]![ThisUser] & "'")

Furthermore, since they both come from the same table, it would simplify
things to use one field instead of two. Bind your User combo box to ID, make
it two columns wide, bind it to the first column, and hide the first column.
This way, it would store the ID but display the user name.

I have a select query that is based on the value of a textbox on my
form. I have another textbox on my form that I want to = the value of
the ID of the query. The query will always return only 1 record. How
do I do this? This is what I have right now, and it is giving me the
following error: #Name?
This is in the textbox that I have set to = the ID field of my query:
=[FindEmployeeID]![ID]

My query is a select query with the following criteria:
[Forms]![EnterNewObservation]![ThisUser]

ThisUser is a textbox on my current form as well.
What should I do differently?

Thanks for your help Brian. I actually am able to eliminate alot of
extra unneeded queries with this little dlookup thing. Very useful.

still learning access, so I'm finding myself going back and doing some
things over...lol
 

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