VBA Microsoft Access Check boxes not filtering data
up vote
0
down vote
favorite
On Form 002_Criteria, I have a checkbox. Currently it does nothing, and I would like for these check boxes to display related data under that field that is checked in a List Box on Form 003_Species. The list box is rowsource is a query know as qSciName. It currently has all the scientific name showing in the list box. The query has multiple tables such as PlantSpecies with field names like PlantSpeciesID, SciName, ComName and another table know as Criteria has the SciName criteria.
I tried the following coding and it did not filter my the results in the list box. I also tried listing the fields in the query and using the criteria to point the check box. When I did this and the more fields I add, it would subtract the Scientific Names until nothing displayed. What can you do to get my code to work properly?
Thank you for help :)
Private Sub Refilter()
Dim strFilterString As String
'BUILD THE FILTER STRING:
If Forms("002_Criteria").CKNFixer = True Then
strFilterString = strFilterString & " OR NFixer ='True'"
End If
If Forms("002_Criteria").CkSun = True Then
strFilterString = strFilterString & " OR TolerantSun ='True'"
End If
If Forms("002_Criteria").CKShade = True Then
strFilterString = strFilterString & " OR TolerantShade ='True'"
End If
If Forms("002_Criteria").CKWind = True Then
strFilterString = strFilterString & " OR TolerantWind ='True'"
End If
If Forms("002_Criteria").CkSalt = True Then
strFilterString = strFilterString & " OR TolerantSalt ='True'"
End If
If Forms("002_Criteria").CkPollinator = True Then
strFilterString = strFilterString & " OR Pollinator ='True'"
End If
If Forms("002_Criteria").CkNative = True Then
strFilterString = strFilterString & " OR Native ='True'"
End If
If Forms("002_Criteria").CKIntroduce = True Then
strFilterString = strFilterString & " OR introduce ='True'"
End If
'REMOVE LEADING " OR " ON FILTER STRING:
If strFilterString <> "" Then strFilterString = Mid(strFilterString, 5)
'APPLY FILTER STRING TO 003_Species:
If strFilterString <> "" Then
Forms("003_Species").ListSciName.RowSource = "SELECT * FROM [qSciName] WHERE " & strFilterString
Else
Forms("003_Species").ListSciName.RowSource = "qSciName"
End If
End Sub
ms-access access-vba
add a comment |
up vote
0
down vote
favorite
On Form 002_Criteria, I have a checkbox. Currently it does nothing, and I would like for these check boxes to display related data under that field that is checked in a List Box on Form 003_Species. The list box is rowsource is a query know as qSciName. It currently has all the scientific name showing in the list box. The query has multiple tables such as PlantSpecies with field names like PlantSpeciesID, SciName, ComName and another table know as Criteria has the SciName criteria.
I tried the following coding and it did not filter my the results in the list box. I also tried listing the fields in the query and using the criteria to point the check box. When I did this and the more fields I add, it would subtract the Scientific Names until nothing displayed. What can you do to get my code to work properly?
Thank you for help :)
Private Sub Refilter()
Dim strFilterString As String
'BUILD THE FILTER STRING:
If Forms("002_Criteria").CKNFixer = True Then
strFilterString = strFilterString & " OR NFixer ='True'"
End If
If Forms("002_Criteria").CkSun = True Then
strFilterString = strFilterString & " OR TolerantSun ='True'"
End If
If Forms("002_Criteria").CKShade = True Then
strFilterString = strFilterString & " OR TolerantShade ='True'"
End If
If Forms("002_Criteria").CKWind = True Then
strFilterString = strFilterString & " OR TolerantWind ='True'"
End If
If Forms("002_Criteria").CkSalt = True Then
strFilterString = strFilterString & " OR TolerantSalt ='True'"
End If
If Forms("002_Criteria").CkPollinator = True Then
strFilterString = strFilterString & " OR Pollinator ='True'"
End If
If Forms("002_Criteria").CkNative = True Then
strFilterString = strFilterString & " OR Native ='True'"
End If
If Forms("002_Criteria").CKIntroduce = True Then
strFilterString = strFilterString & " OR introduce ='True'"
End If
'REMOVE LEADING " OR " ON FILTER STRING:
If strFilterString <> "" Then strFilterString = Mid(strFilterString, 5)
'APPLY FILTER STRING TO 003_Species:
If strFilterString <> "" Then
Forms("003_Species").ListSciName.RowSource = "SELECT * FROM [qSciName] WHERE " & strFilterString
Else
Forms("003_Species").ListSciName.RowSource = "qSciName"
End If
End Sub
ms-access access-vba
1
Fields likeTolerantShade
are a string or Yes/No? If Yes/No, then remove single quotes.
– Sergey S.
Nov 20 at 3:22
Sergey S. They are Yes/No, I did remove the single and vba still did nothing with filtering the list box.
– Tim
Nov 20 at 5:06
1
Does your final query, which you set to theRowSource
property work well, if you run it by hand, for example by creating a new query object?
– Unhandled Exception
Nov 20 at 7:59
1
Are you sure aboutOR
? Maybe you need to useAND
instead?
– Sergey S.
Nov 20 at 8:01
I will try replace or with and, I dont think it will make a difference at all as should have been doing something by now.
– Tim
Nov 20 at 16:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
On Form 002_Criteria, I have a checkbox. Currently it does nothing, and I would like for these check boxes to display related data under that field that is checked in a List Box on Form 003_Species. The list box is rowsource is a query know as qSciName. It currently has all the scientific name showing in the list box. The query has multiple tables such as PlantSpecies with field names like PlantSpeciesID, SciName, ComName and another table know as Criteria has the SciName criteria.
I tried the following coding and it did not filter my the results in the list box. I also tried listing the fields in the query and using the criteria to point the check box. When I did this and the more fields I add, it would subtract the Scientific Names until nothing displayed. What can you do to get my code to work properly?
Thank you for help :)
Private Sub Refilter()
Dim strFilterString As String
'BUILD THE FILTER STRING:
If Forms("002_Criteria").CKNFixer = True Then
strFilterString = strFilterString & " OR NFixer ='True'"
End If
If Forms("002_Criteria").CkSun = True Then
strFilterString = strFilterString & " OR TolerantSun ='True'"
End If
If Forms("002_Criteria").CKShade = True Then
strFilterString = strFilterString & " OR TolerantShade ='True'"
End If
If Forms("002_Criteria").CKWind = True Then
strFilterString = strFilterString & " OR TolerantWind ='True'"
End If
If Forms("002_Criteria").CkSalt = True Then
strFilterString = strFilterString & " OR TolerantSalt ='True'"
End If
If Forms("002_Criteria").CkPollinator = True Then
strFilterString = strFilterString & " OR Pollinator ='True'"
End If
If Forms("002_Criteria").CkNative = True Then
strFilterString = strFilterString & " OR Native ='True'"
End If
If Forms("002_Criteria").CKIntroduce = True Then
strFilterString = strFilterString & " OR introduce ='True'"
End If
'REMOVE LEADING " OR " ON FILTER STRING:
If strFilterString <> "" Then strFilterString = Mid(strFilterString, 5)
'APPLY FILTER STRING TO 003_Species:
If strFilterString <> "" Then
Forms("003_Species").ListSciName.RowSource = "SELECT * FROM [qSciName] WHERE " & strFilterString
Else
Forms("003_Species").ListSciName.RowSource = "qSciName"
End If
End Sub
ms-access access-vba
On Form 002_Criteria, I have a checkbox. Currently it does nothing, and I would like for these check boxes to display related data under that field that is checked in a List Box on Form 003_Species. The list box is rowsource is a query know as qSciName. It currently has all the scientific name showing in the list box. The query has multiple tables such as PlantSpecies with field names like PlantSpeciesID, SciName, ComName and another table know as Criteria has the SciName criteria.
I tried the following coding and it did not filter my the results in the list box. I also tried listing the fields in the query and using the criteria to point the check box. When I did this and the more fields I add, it would subtract the Scientific Names until nothing displayed. What can you do to get my code to work properly?
Thank you for help :)
Private Sub Refilter()
Dim strFilterString As String
'BUILD THE FILTER STRING:
If Forms("002_Criteria").CKNFixer = True Then
strFilterString = strFilterString & " OR NFixer ='True'"
End If
If Forms("002_Criteria").CkSun = True Then
strFilterString = strFilterString & " OR TolerantSun ='True'"
End If
If Forms("002_Criteria").CKShade = True Then
strFilterString = strFilterString & " OR TolerantShade ='True'"
End If
If Forms("002_Criteria").CKWind = True Then
strFilterString = strFilterString & " OR TolerantWind ='True'"
End If
If Forms("002_Criteria").CkSalt = True Then
strFilterString = strFilterString & " OR TolerantSalt ='True'"
End If
If Forms("002_Criteria").CkPollinator = True Then
strFilterString = strFilterString & " OR Pollinator ='True'"
End If
If Forms("002_Criteria").CkNative = True Then
strFilterString = strFilterString & " OR Native ='True'"
End If
If Forms("002_Criteria").CKIntroduce = True Then
strFilterString = strFilterString & " OR introduce ='True'"
End If
'REMOVE LEADING " OR " ON FILTER STRING:
If strFilterString <> "" Then strFilterString = Mid(strFilterString, 5)
'APPLY FILTER STRING TO 003_Species:
If strFilterString <> "" Then
Forms("003_Species").ListSciName.RowSource = "SELECT * FROM [qSciName] WHERE " & strFilterString
Else
Forms("003_Species").ListSciName.RowSource = "qSciName"
End If
End Sub
ms-access access-vba
ms-access access-vba
asked Nov 20 at 3:06
Tim
11
11
1
Fields likeTolerantShade
are a string or Yes/No? If Yes/No, then remove single quotes.
– Sergey S.
Nov 20 at 3:22
Sergey S. They are Yes/No, I did remove the single and vba still did nothing with filtering the list box.
– Tim
Nov 20 at 5:06
1
Does your final query, which you set to theRowSource
property work well, if you run it by hand, for example by creating a new query object?
– Unhandled Exception
Nov 20 at 7:59
1
Are you sure aboutOR
? Maybe you need to useAND
instead?
– Sergey S.
Nov 20 at 8:01
I will try replace or with and, I dont think it will make a difference at all as should have been doing something by now.
– Tim
Nov 20 at 16:47
add a comment |
1
Fields likeTolerantShade
are a string or Yes/No? If Yes/No, then remove single quotes.
– Sergey S.
Nov 20 at 3:22
Sergey S. They are Yes/No, I did remove the single and vba still did nothing with filtering the list box.
– Tim
Nov 20 at 5:06
1
Does your final query, which you set to theRowSource
property work well, if you run it by hand, for example by creating a new query object?
– Unhandled Exception
Nov 20 at 7:59
1
Are you sure aboutOR
? Maybe you need to useAND
instead?
– Sergey S.
Nov 20 at 8:01
I will try replace or with and, I dont think it will make a difference at all as should have been doing something by now.
– Tim
Nov 20 at 16:47
1
1
Fields like
TolerantShade
are a string or Yes/No? If Yes/No, then remove single quotes.– Sergey S.
Nov 20 at 3:22
Fields like
TolerantShade
are a string or Yes/No? If Yes/No, then remove single quotes.– Sergey S.
Nov 20 at 3:22
Sergey S. They are Yes/No, I did remove the single and vba still did nothing with filtering the list box.
– Tim
Nov 20 at 5:06
Sergey S. They are Yes/No, I did remove the single and vba still did nothing with filtering the list box.
– Tim
Nov 20 at 5:06
1
1
Does your final query, which you set to the
RowSource
property work well, if you run it by hand, for example by creating a new query object?– Unhandled Exception
Nov 20 at 7:59
Does your final query, which you set to the
RowSource
property work well, if you run it by hand, for example by creating a new query object?– Unhandled Exception
Nov 20 at 7:59
1
1
Are you sure about
OR
? Maybe you need to use AND
instead?– Sergey S.
Nov 20 at 8:01
Are you sure about
OR
? Maybe you need to use AND
instead?– Sergey S.
Nov 20 at 8:01
I will try replace or with and, I dont think it will make a difference at all as should have been doing something by now.
– Tim
Nov 20 at 16:47
I will try replace or with and, I dont think it will make a difference at all as should have been doing something by now.
– Tim
Nov 20 at 16:47
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385633%2fvba-microsoft-access-check-boxes-not-filtering-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Fields like
TolerantShade
are a string or Yes/No? If Yes/No, then remove single quotes.– Sergey S.
Nov 20 at 3:22
Sergey S. They are Yes/No, I did remove the single and vba still did nothing with filtering the list box.
– Tim
Nov 20 at 5:06
1
Does your final query, which you set to the
RowSource
property work well, if you run it by hand, for example by creating a new query object?– Unhandled Exception
Nov 20 at 7:59
1
Are you sure about
OR
? Maybe you need to useAND
instead?– Sergey S.
Nov 20 at 8:01
I will try replace or with and, I dont think it will make a difference at all as should have been doing something by now.
– Tim
Nov 20 at 16:47