Help with select case on combobox (1 Viewer)

stevekos07

Registered User.
Local time
Yesterday, 21:32
Joined
Jul 26, 2015
Messages
174
I have a table where I have client information including fields for weekdays. I elected to use separate fields for the days of the week for this table, which are Boolean fields.

What I want to do is to set up a form where I can select the day of the week from a combobox with weekdays as values, then an AfterUpdate event on the combobox that will filter the form by the field of the same name with the value of "True".

I believe that this can be best achieved with a Select Case, but I am not very confident with this method.

What would be the approach here?
 

Beetle

Duly Registered Boozer
Local time
Yesterday, 22:32
Joined
Apr 30, 2011
Messages
1,808
It is generally not a good idea to store data in this manner, however, if you want to do this I don't really see a need for a Select Case here based on your description. You are going to use a combo box with weekday names (based on another table, or value list). After the selection in the combo box, you will not be looking for data in your table, but rather field names. This could be done with something as simple as the following in the After Update event of the combo box (you will need to correct for your actual combo box name);

Code:
Private Sub cboWeekday_AfterUpdate()
    
    With Me
        .Filter = Me!cboWeekday & " = True"
        .FilterOn = True
    End With
    
End Sub

You may also want to provide a way for your users to remove the filter (FilterOn = False) via a command button or something.

Additionally, you may want to have a look at this link for some of the potential pitfalls of storing data like this. Just FYI.
 

stevekos07

Registered User.
Local time
Yesterday, 21:32
Joined
Jul 26, 2015
Messages
174
Thanks, yes this worked!

Regarding the multiple yes/no fields issue, yes, I certainly observe standardisation for most fields, but for day of the week fields, it is not such a problem as there is not likely to ever be a new day of the week added, which would cause problems.

I tried a many-to-many table for this particular application in our database but I found that I got into all sorts of problems with a particularly complex situation, so after consulting with a professional firm we decided that for this particular application it would not kill anyone to have multiple day fields for days of the week.

(By the way your signature should include a loop until full!)

Cheers.
 

Users who are viewing this thread

Top Bottom