Auto populate combo box if its query source is only 1 record

A

Andrew P.

Hi All

I have a form used to select records from query and add them to a table. 4
combos are used to drill the selection down to find the record to add.
1 Combo is the name of the record.
The other 3 combos are from single field queries I made (that query the
query mentioned above) to get single value output to feed the combos (this is
probably not the best way to do it Im well aware, but the only way I could
figure out...)

I want each of the combos to fill in automatically when the query source of
that particular combo finds only 1 record.

I have tried this in the builder for the after update for the combo:
Line 1: Action: Requery
Line 2: Condition: Count([Unique2Book]![Book])
Action: SetValue
Arguements: [Forms]![AddToWeeklyList]![Combo28],
[Unique2Book]![Book]

With the idea being to duplicate line 2 but fill with the other combos, and
then put the same code into the other combos after update. Unfortunately this
throws errors back at me.

If anyone can help, that would be much appreciated!
Regards
Andrew
 
A

Allen Browne

To use a macro to assign the first item of the combo as its value if it
contains only one item:

Condition:
[Forms]![AddToWeeklyList]![Combo28].ListCount = 1

Action: SetValue
Item: [Forms]![AddToWeeklyList]![Combo28]
Expr: [Forms]![AddToWeeklyList]![Combo28].ItemData(0)
 
A

Andrew P.

Superb! Thanks for that, working really well now.
Regards
Andrew

Allen Browne said:
To use a macro to assign the first item of the combo as its value if it
contains only one item:

Condition:
[Forms]![AddToWeeklyList]![Combo28].ListCount = 1

Action: SetValue
Item: [Forms]![AddToWeeklyList]![Combo28]
Expr: [Forms]![AddToWeeklyList]![Combo28].ItemData(0)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Andrew P. said:
Hi All

I have a form used to select records from query and add them to a table. 4
combos are used to drill the selection down to find the record to add.
1 Combo is the name of the record.
The other 3 combos are from single field queries I made (that query the
query mentioned above) to get single value output to feed the combos (this
is
probably not the best way to do it Im well aware, but the only way I could
figure out...)

I want each of the combos to fill in automatically when the query source
of
that particular combo finds only 1 record.

I have tried this in the builder for the after update for the combo:
Line 1: Action: Requery
Line 2: Condition: Count([Unique2Book]![Book])
Action: SetValue
Arguements: [Forms]![AddToWeeklyList]![Combo28],
[Unique2Book]![Book]

With the idea being to duplicate line 2 but fill with the other combos,
and
then put the same code into the other combos after update. Unfortunately
this
throws errors back at me.

If anyone can help, that would be much appreciated!
Regards
Andrew
 

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