subform combo box

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Access Training and help » Subform / combo box

Subform / combo box

resolvedResolved · High Priority · Version 2003

Neal has attended:
Access Advanced course

Subform / combo box

Hi
I have a combo box that selects the country data from my table and opens a form. In the form the country data is shown in a subform. I now want to add a combo box to the form that filters the sub form data so that I only view the data for a selected town
Help
Thanks

RE: subform / combo box

Any luck with an answer?

RE: subform / combo box

Hi Neal, note that I am delegate not a tutor but feel sure I can help.

Firstly I don't understand your first sentence. So if my guessed solutions below are not what you need then you can reply with more information such as, is your subform based directly on a table, a query or a form?

You can add a combo box into the subform and select the wizard option 'Find a record on my form based on the value I selected in my combo box'. Then select the town field and complete. You can then select from the drop down list or type in the town. You need to click out of the box for it to go. I like adding a small save or refresh button next to the drop down and put text on it saying 'Go' to make this intuitive.

Another solution if you don't mind re-inserting the subform is to choose to make the subform match a value on the main form (during the creation with the Wizard). If town is a natural ingredient of the main form and the main form is single (one record per form) then the subform will automatically go the correct town without any need to select from a combo box. Other solutions I can give depend on what the main form is based on, but options might include creating a simple small table to 'fool' the system. That table would have primary key and one field (call it SearchTown if you like), then include that table in the query that supplies the form and insert a combo box for that field. When you then create the subform you match the subform field Town to SearchTown. For the combo box (drop down list) source you insert a query to list the towns from where these are stored (using group by to list each once if needed).

RE: subform / combo box

Hi Mark

Thanks for your help. Therefore I have created a Form with the fields I want to via from my query. I have named it 'subformmain'. I have then created a Form named 'Main' and have added a subform using the wizard and have selected 'subformmain'. I added a combobox using the wizard and selected the option to select a value on my form from the 'country' field. Now if I add another combobox to filter the country by 'town' again using the wizard, select a value of my form it does select the town but when I open the combobox I see all the towns in the table/query and when a twon is selected it returns all the towns for that country.

Any ideas?

Thanks

RE: subform / combo box

Hello again Neal,

I'm not sure if you are putting the combos in the subform or main form. There is a 'classic' problem and answer case for twin combos to be found in text books which seem to just launch into vba code regardless. However, I often find there are ways round not having to use code.

If you can tell me if the country and town fields are in the same table, and whether or not the data behind the main part of the form is related (and how) to the subform then we may be able to get at least one of the two fields filtered by one means and the other by a different one.

Regard, Mark


 

Access tip:

Calculating The Difference Between Dates

If you wish to calculate the time between two date fields, this can be done in a number of ways:

1. As a calculated field in a query
2. As a calculated control in a form or report
3. As a calculation in a VBA procedure.

The basic syntax to get the number of days between two dates is:

=[One Date Field] - [Another Date Field]

You can also use one of the following functions:

=Month([One Date Field] - [Another Date Field])
which calculates the number of months between the two fields

=Year([One Date Field] - [Another Date Field])
which calculates the number of years between the two fields.

Another function is the DateDiff() function.

It uses an argument to determine how the time interval is measured. For example:

=DateDiff("q",[One Date Field] - [Another Date Field])
returns the number of quarters between the two fields.

Other intervals that can be used in this expression are as follows:
"yyyy" - Years
"m" - Months
"d" - Days
"w" - Weekdays
"ww" - Weeks
"h" - Hours
"n" - Minutes
"s" - Seconds

View all Access hints and tips


Server loaded in 0.08 secs.