Selection Box (1 Viewer)

Space Cowboy

Member
Local time
Today, 13:54
Joined
May 19, 2024
Messages
131
If I have a selection box with ten identifiers France, England, USA, Ireland etc

Can I configure it somehow to filter on that selection?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:54
Joined
May 7, 2009
Messages
19,268
is the selection box a combobox? yes you can filter the Form.
add code to the AfterUpdate event of the combobox:
Code:
Private Sub TheCombobox_AfterUpdate()
    If Me.TheCombobox.ListIndex < 0 Then
        DoCmd.ShowAllRecords
    Else
        DoCmd.ApplyFilter , "FieldName = '" & Me.TheCombobox & "'"
    End If
End Sub
 

Space Cowboy

Member
Local time
Today, 13:54
Joined
May 19, 2024
Messages
131
Thanks Arnelgp
In theory, can two or three "Conditions" be conjoined or will that have to go through Sub Forms?
 

Mike Krailo

Well-known member
Local time
Today, 08:54
Joined
Mar 28, 2020
Messages
1,139
If you have multiple combo boxes, then you would have to update or filter out the previous selections for each subsequent selection, but I would think it would be easier to use a multiselect list box that would build a filter string, then after you press a button, it would do the filtering.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:54
Joined
May 7, 2009
Messages
19,268
it's hard to explain without any concrete example for you to study.
look at product form and see the code on the AfterUpdate event of the Country Listbox.
 

Attachments

  • demo.accdb
    488 KB · Views: 21

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:54
Joined
May 21, 2018
Messages
8,748
To configure a Listbox to be multiselect go to the "Other" tab and in the property "Multi Select" pick "Simple"
 

Space Cowboy

Member
Local time
Today, 13:54
Joined
May 19, 2024
Messages
131
What kind of selections are you talking about? Check boxes or combo box single selections?
Hi Mike,

I have not made a form before, I dont know what the correct type of box will be, trying to find out the right way before I start. I have read a few articles on forms and watched some videos on Youtube but non seem to show this.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:54
Joined
Sep 12, 2006
Messages
15,796
You would be better having an identifier table with a numbered index.

So 1 = England, 2=France etc.

That way you test for the numeric value. If you want to change England to UK, Czech Republic to Czechia, you can do without affecting any code.

You may be able to add new countries as well depending how your app deals with the selection..
 

GPGeorge

George Hepworth
Local time
Today, 05:54
Joined
Nov 25, 2004
Messages
2,136
Hi Gemma the husky

can you please direct me to an article that explains what you mean?
This is often referred to as a Lookup table. It is a table in which you list all of the valid values for an entity, e.g. "Countries". That lookup table can grow as additional values are needed, simply by adding a record for the new value.

That table is the row source for a combo box or a list box.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:54
Joined
Sep 12, 2006
Messages
15,796
Create a table, called countries, with your various countries. Have a number column -autonumber would be a good idea.

In your customer Data, or sales data, or whatever you are trying to filter, add a column called Country code, as a number, (long integer). Set the field type as combo box, and the wizard will let you pick the country table and set it up for you.

When you add countrycode to a form, it will then automatically be shown as a working combo box. You can do all this manually, but using automation will let you see how it works anyway. Most of us probably do it manually as we prefer to make some of the choices ourselves.

The country will be stored as the numeric value, but will be displayed as the text value from the countries table corresponding to the selected number
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:54
Joined
May 21, 2018
Messages
8,748
I dont know what the correct type of box will be, trying to find out the right way before I start. I have read a few articles on forms and watched some videos on Youtube but non seem to show this.
@arnelgp provided a working demo, can you at least say if that is what you want? If not what would you like different?
 

Space Cowboy

Member
Local time
Today, 13:54
Joined
May 19, 2024
Messages
131
@arnelgp provided a working demo, can you at least say if that is what you want? If not what would you like different?
That would do nicely!
It did not work correctly as my access would not run it due to dangerous executable code. but I managed one attempt at a filter and it worked.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:54
Joined
May 21, 2018
Messages
8,748
That would do nicely!
It did not work correctly as my access would not run it due to dangerous executable code. but I managed one attempt at a filter and it worked.
When you download a dB you need to right click and go to proprties. Select Unblock.
unblock.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:54
Joined
Sep 21, 2011
Messages
14,713
I do not get that window? possibly because I am using Explorer Patcher on Win11?
What about Trust location?
I download all my db's to a temp folder and have trusted that.
1719425998186.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:54
Joined
May 21, 2018
Messages
8,748
Yes there are cases where the Web mark is not added or moved to trusted location.
 

Users who are viewing this thread

Top Bottom