Populate combo box from current record

  • Thread starter Syed Zeeshan Haider
  • Start date
S

Syed Zeeshan Haider

Hello Everybody,
I am working with MS Access 2003 and I am trying to populate a combo box
with data from different fields of current record only. For example, three
fields in current record get three different nick names. A fourth field is a
combo box and in this the user can choose one of three nick names previously
entered in the last three fields. Populating the combo box is not actually a
problem as it can be done by using Requery in VBA with the use of proper
events. However, I want to populate this combo box with the data of
above-mentioned three fields from current record only. My query picks up
data from all the records of current table. I am using UNION query to
combine the data of three fields but how to tell the query to use only
current record as data source?

Any will be highly appreciated.

Thank you,
 
A

Arvin Meyer [MVP]

Use a reference to the PrimaryKey field in the criteria of the query, and
requery it as necessary:

[Forms]![FormName]![ControlName]

or by drilling down using the Build button from the right-click menu in the
Criteria box.l

In the AfterUpdate event of each of the textboxes, create an event
procedure, with a single line of code:

Me.Requery
 
S

Syed Zeeshan Haider

Arvin Meyer said:
Use a reference to the PrimaryKey field in the criteria of the query, and
requery it as necessary:

[Forms]![FormName]![ControlName]

or by drilling down using the Build button from the right-click menu in
the Criteria box.l

I was actually creating a query for Row Source property of a field in Tables
Design View where explicit reference to PrimaryKey field's doesn't seem to
be possible. Next option that comes to my mind is changing the relevant
field's Row Source property in the form with VBA and the property would have
query with explicit reference to current record PrimaryKey.
 
A

Arvin Meyer [MVP]

Syed Zeeshan Haider said:
Arvin Meyer said:
Use a reference to the PrimaryKey field in the criteria of the query, and
requery it as necessary:

[Forms]![FormName]![ControlName]

or by drilling down using the Build button from the right-click menu in
the Criteria box.l

I was actually creating a query for Row Source property of a field in
Tables Design View where explicit reference to PrimaryKey field's doesn't
seem to be possible. Next option that comes to my mind is changing the
relevant field's Row Source property in the form with VBA and the property
would have query with explicit reference to current record PrimaryKey.

Both of those should work. Generally, a saved query is easier to maintain,
but it isn't necessary. Just remember to requery the combo using the
AfterUpdate event of the data entry controls.
 

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