christine407
New member
- Local time
- Today, 05:51
- Joined
- Jan 18, 2021
- Messages
- 13
Hello, new to VBA. I apologize for starting what seems like an infinitely duplicate thread, but the forum rules seem to indicate this is ok. I have the standard challenge of filtering a form based on multiple combo boxes. I’ve watched a few tutorials and I’ve managed to get myself a little confused. Eventually, I have to hyperlink the unique ID of the form to go to another form, but baby steps and baby steps for me. I’ve successfully set up the form part. Took me a while to find the right video to set up the tabular/continuous table set. I am placing my combo boxes in the header portion of the form.
I have three general questions:
(1) When using the combo box wizard, do I want to select I want the combo box to get the values from another table or Query or find a record on my form based on the value I selected in my combo box? I normally use the first option but I’m seeing tutorials that use the second option as well.
(2) This thread (titled multiple combo box filters in a form posted by Tskutnik in Nov 2020) caught my eye. I had planned on building a filter string based on the selection within the combo boxes, but the last two post indicates it might not be the best idea if you are working with a table that comes from ODBC. In my case, my table is obtained through ODBC connections. If building a filtering SQL string is not a good idea, can someone provide a little more context for why this isn’t a good idea?
(3) For the filtering, I’ve seeing different approaches for having the multiple combo boxes. For the time being, I’ve settled on the following general approach below (although I could be swayed to do it differently). My question is how to I apply the filter string to the form, is it under row source? The original example I was reviewing used this approach to apply the filter string to subsequent combo boxes so that the user did not have to use the combo boxes in a strict cascading order. So if the user selects a country, the available cities in the next combo box correspond to that country. Here is my general intended approach for the interactive combo boxes. I just don’t quite follow where to apply the filter (or if I need to make a separate one) for the form. Thank you!
I have three general questions:
(1) When using the combo box wizard, do I want to select I want the combo box to get the values from another table or Query or find a record on my form based on the value I selected in my combo box? I normally use the first option but I’m seeing tutorials that use the second option as well.
(2) This thread (titled multiple combo box filters in a form posted by Tskutnik in Nov 2020) caught my eye. I had planned on building a filter string based on the selection within the combo boxes, but the last two post indicates it might not be the best idea if you are working with a table that comes from ODBC. In my case, my table is obtained through ODBC connections. If building a filtering SQL string is not a good idea, can someone provide a little more context for why this isn’t a good idea?
(3) For the filtering, I’ve seeing different approaches for having the multiple combo boxes. For the time being, I’ve settled on the following general approach below (although I could be swayed to do it differently). My question is how to I apply the filter string to the form, is it under row source? The original example I was reviewing used this approach to apply the filter string to subsequent combo boxes so that the user did not have to use the combo boxes in a strict cascading order. So if the user selects a country, the available cities in the next combo box correspond to that country. Here is my general intended approach for the interactive combo boxes. I just don’t quite follow where to apply the filter (or if I need to make a separate one) for the form. Thank you!
Code:
cboABC_AfterUpdate()
BuildFiltStr
End Sub
--
Private Sub cboABC_GotFocus()
Me.AllowEdits = True
If Nz(FiltStr, "") = "" Then
Me.FiltABC.RowSource = "SELECT DISTINCT TABLE.ABC_NAME FROM TABLE; "
Else
Me.FiltABC.RowSource = "SELECT DISTINCT TABLE.ABC_NAME FROM TABLE WHERE " & FiltStr & ";"
End If
End Sub
--
Sub BuildFiltStr()
'Make where condition blank at the beginning of the routine
FiltStr = ""
'If a field has been selected, change the filter string to include the field condition
If Me!FiltABC <> "" Then
FiltStr = "[BOTM_FLD_NAME_CD] = '" & Me!FiltABC & "'"
End If
'If no conditions have been set, then change make filter false
If FiltStr = "" Then
Me.Filter = ""
Me.FilterOn = False
Else
Me.Filter = FiltStr
Me.FilterOn = True
End If
End Sub