If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > combo box trickery

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-12, 12:52
fatboy_jim fatboy_jim is offline
Registered User
 
Join Date: Jul 2012
Posts: 4
combo box trickery

Hi all,

My Name's Jim. This is my first post on this site, I'm relatively new to databases. I started learning about this stuff a few weeks ago to make a database for work. I won't go into the details if I can help it because i'm into the nitty gritty of getting the forms to look nice and do something useful. The data structure and all that are ok, I had help with that from a friend who's a pro. I can't be constantly bugging him while he's at work though so for some of the details It'd be great to get some help from you lovely folks

My first question is about filtering a subform. Here goes..

I have made a form which contains a subform that displays the results of a select query on one of my tables. I'd like to be able to use combo boxes to filter that subform to display certain information. If there were only one field I wanted to filter by then I believe the solution is straightforward. If I'm not mistaken you would add the combo box control as the criterion in the query the subform is based on and use the onUpdate event of the combo box to requery the subform, sound about right?

Well, the tricky thing is that I'd like (in an ideal world) to have the freedom to filter by any of the fields. Having a combo box for each is pretty ugly but I found I can make a combo box with a field list for my query, so what I'm wondering is this..

Can I have two combo boxes. Box1 = field list for my query. Box2 = all unique values in the field chosen by Box1. And then, filter the subform by making a select query like

SELECT *
FROM Query
WHERE [Box1] (chosen field) =[Box2] (chosen value)

??

Alternatively, what would be even nicer is if I could search the subform and display all records containing a given string or number in a given field. In which case you would choose the field to search in a combo box and then search that field with a txt box, displaying all the records that matched.

Forgive me for going on, I'm just thinking out loud as it were so you know what I'm trying to do and maybe somebody has done something similar in the past.

Any help would be appreciated.

Thanks
Jim.
Reply With Quote
  #2 (permalink)  
Old 07-20-12, 11:37
sps sps is offline
Registered User
 
Join Date: Aug 2004
Location: Cary, NC
Posts: 264
I don't see why not... If combo one contains the actual field names and combo two contains the actual values it should work out just fine. You would just use something like

Code:
sql = "select * from Query where " & me.Box1 & " = '" & me.Box2  & "'"
__________________

Steve
Reply With Quote
  #3 (permalink)  
Old 07-23-12, 07:49
fatboy_jim fatboy_jim is offline
Registered User
 
Join Date: Jul 2012
Posts: 4
Thanks. Using the & signs was something I hadn't seen before, it's opened up a whole new world
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On