crazy_ivan_1
New member
- Local time
- Today, 15:21
- Joined
- Jun 7, 2020
- Messages
- 23
Hi All,
I have been browsing here and stack exchange for help with syntax and getting my combo boxes to work on my form.
The first combo is ins_filter_cmb. This gets it record sources from a query but there is also a UNION to add an "All" at the top of the list. This is a list of instrument categories.
The second combo is ins_select_cmb. I am trying to create a filter that restricts this box based on the instrument category of the first box but only where the field instrument_steri_yes is true
This is my VBA for the second combo
What I am trying to do is:
If the first box says "All", then all the instruments are listed where instrument_steriyes is TRUE, otherwise the listed instruments are based on their category. The combo box only shows the instrument_ategory and the instrument_name
When I run the form, the All filter does not work at all and when I select a caterogy, I get an Input Prompt for the category (which is listed in the title of the prompt), where when I fill in the category name in the input field, it filters the combobox then.
I am trying to figure out where my syntax is incorrect.
I have been browsing here and stack exchange for help with syntax and getting my combo boxes to work on my form.
The first combo is ins_filter_cmb. This gets it record sources from a query but there is also a UNION to add an "All" at the top of the list. This is a list of instrument categories.
Code:
SELECT [tbl_instrument_cat].[instrument_category], [tbl_instrument_cat].[instrument_cat_ID] FROM tbl_instrument_cat UNION SELECT "All","0" FROM tbl_instrument_cat ORDER BY tbl_instrument_cat.instrument_cat_ID;
The second combo is ins_select_cmb. I am trying to create a filter that restricts this box based on the instrument category of the first box but only where the field instrument_steri_yes is true
This is my VBA for the second combo
Code:
Private Sub ins_filter_cmb_AfterUpdate()
If Me.ins_filter_cmb.Value = "All" Then
'If IsNull(Me.ins_filter_cmb.Value) Then
Me.ins_select_cmb.RowSource = "SELECT instrument_name, instrument_steriyes, instrument_category " & _
"FROM tbl_instruments " & _
"WHERE instrument_category = '*' " & _
" AND instrument_steriyes = '-1'"
Me.ins_select_cmb.Requery
Else
'Me.ins_select_cmb.Value = ""
'Me.ins_select_cmb.Requery
Me.ins_select_cmb.RowSource = "SELECT instrument_name, instrument_steriyes, instrument_category " & _
"FROM tbl_instruments " & _
"WHERE instrument_category = " & Me.ins_filter_cmb & _
" AND instrument_steriyes = '-1'"
Me.ins_select_cmb.Requery
End If
End Sub
What I am trying to do is:
If the first box says "All", then all the instruments are listed where instrument_steriyes is TRUE, otherwise the listed instruments are based on their category. The combo box only shows the instrument_ategory and the instrument_name
When I run the form, the All filter does not work at all and when I select a caterogy, I get an Input Prompt for the category (which is listed in the title of the prompt), where when I fill in the category name in the input field, it filters the combobox then.
I am trying to figure out where my syntax is incorrect.