How run a query nased on combo box selection (2 Viewers)

Invader89

Registered User.
Local time
Today, 08:29
Joined
Sep 22, 2015
Messages
29
How run a query based on combo box selection

Hi guys. I'm an access newbie and I have searched for hours online on this subject line stated above.
 
Last edited:

bob fitz

AWF VIP
Local time
Today, 12:29
Joined
May 23, 2011
Messages
4,717
You need to add some criteria to the query so that it only returns values equal to the one selected in the combo box.
Once a selection is made in the combo box its value is a number representing the Primary Key field of the table it is based on so you would need to add that field to your query first (so that you can then add a reference to the combo box on the form) in the criteria row of the query.
I have done this for you the query called SearchbySupp in the attached db.

However, IMHO it would be better to use the query as the data source and display the results in a form, perhaps as a subform on your main form. I would not expose a query like this to the user.
 
Last edited:

Invader89

Registered User.
Local time
Today, 08:29
Joined
Sep 22, 2015
Messages
29
You need to add some criteria to the query so that it only returns values equal to the one selected in the combo box.
Once a selection is made in the combo box its value is a number representing the Primary Key field of the table it is based on so you would need to add that field to your query first (so that you can then add a reference to the combo box on the form) in the criteria row of the query.
I have done this for you the query called SearchbySupp in the attached db.

However, IMHO it would be better to use the query as the data source and display the results in a form, perhaps as a subform on your main form. I would not expose a query like this to the user.


Thanks so much for the help! Your suggestion sounds good. But how would I go along into showing the results on main form? both the combo boxes will reference different queries so I'm not sure how two subforms will fit on the form if thats the route to take.

Is there a way to position the subforms so they don't overlap are positioned differently?
 

bob fitz

AWF VIP
Local time
Today, 12:29
Joined
May 23, 2011
Messages
4,717
Thanks so much for the help! Your suggestion sounds good. But how would I go along into showing the results on main form? both the combo boxes will reference different queries so I'm not sure how two subforms will fit on the form if thats the route to take.

Is there a way to position the subforms so they don't overlap are positioned differently?
Well one way would be to have a tab control on the main form with each form on a separate tab.

My personal preference would be to create the two subforms and have them both hidden. In the After Update event of each combo box you could have code to make visible the correct subform and hide the other.
 

Invader89

Registered User.
Local time
Today, 08:29
Joined
Sep 22, 2015
Messages
29
Well one way would be to have a tab control on the main form with each form on a separate tab.

My personal preference would be to create the two subforms and have them both hidden. In the After Update event of each combo box you could have code to make visible the correct subform and hide the other.

Thanks so much
 
Last edited:

bob fitz

AWF VIP
Local time
Today, 12:29
Joined
May 23, 2011
Messages
4,717
That sounds really neat! I know you've help me out a lot already but could you please provide an example like you did with db? I've attached an update file. I'm no coder by any means and this was pushed on to me without my input.

Thanks again.
Try the attached db.
Post back if you have any questions.
 
Last edited:

Invader89

Registered User.
Local time
Today, 08:29
Joined
Sep 22, 2015
Messages
29
Try the attached db.
Post back if you have any questions.


I believe I figured it out. I think it had to do with the individual subforms and how there were null 'Link Master fields' and 'Link Child fileds' when i tried replicating your results. Let me know if that would the case for getting no results.

The issue i was having before was no results showing up.
 

bob fitz

AWF VIP
Local time
Today, 12:29
Joined
May 23, 2011
Messages
4,717
I haven't looked at your db but null values in 'Link Master fields' and 'Link Child fields' properties was the first thing I would have looked at.
Is it working OK now?
 

Invader89

Registered User.
Local time
Today, 08:29
Joined
Sep 22, 2015
Messages
29
I haven't looked at your db but null values in 'Link Master fields' and 'Link Child fields' properties was the first thing I would have looked at.
Is it working OK now?

Looks like its working fine now.
 

Invader89

Registered User.
Local time
Today, 08:29
Joined
Sep 22, 2015
Messages
29
Good :):)
Glad you got it working ok.

One more question Bob. What if I wanted my combo box to look up by more than one player name.

Again, I'm terrible at coding.
Thanks
 
Last edited:

Users who are viewing this thread

Top Bottom