Pass Result From Query to a field on a subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a combo box to look up department names. When I select the
Department name, I need to also get the Department number in the same table.

I do not know how to get the number at the time I am picking the name.

The way I have partially solved this is to pass the Name to a query and pull
up the number. That works great. I don;t know how to pass that field in the
query back to the field on my subform.

Any help would be SOOO appreciated.
 
Include the DeptNo in the RowSource of the ComboBox and use the Column
Property of the ComboBox to obtain the DeptNo of the selected row.
 
Hi, Ron.
I do not know how to get the number at the time I am picking the name.

Create a new query such as the following:

SELECT DeptNo, DeptName
FROM tblDepartments
ORDER BY DeptName;

Change the names to match yours, then save the query. In your combo box's
properties, the combo box's Bound Column Property is set to 1, the Column
Count Property is set to 2, and the Column Widths Property is set to 0";1" so
that the first column is hidden.

To retrieve the value in the first column (the corresponding DeptNo for the
selected DeptName), use the combo box's Column Property in VBA code:

Me!cboDept.Column(0)

.. . . where cboDept is the name of the combo box, and 0 is the first column
in the combo box.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Thanks a lot. Can hardly wait to test this. But you gave me the info on how
to access the other info in the combo box. I didn't know how to look up.

THANKS!!!
 
Back
Top