I have a related thread here: thread703-1581216 if you want background.
I am using this method to create different report menus, which works great. Users can choose what type of report they want and then go to that report menu. If it is say a menu for Car Manufacturers, they have 2 list boxes. 1 for manufacturers and 1 for car models.
The list boxes are populated by just that field based on the main databse table for the info that has been filled in for all records (ie. some customer records do not have the car manufacturer or model filled out.)
Here is my challenge. I have this set up so that users can choose 1 or more of the values in either of the 2 listboxes and then click to get a subform (visible) with a grid (datasheet) layout that they can take to Excel or hit another button and get a formatted report.
This is the code that I have been working on:
The part I am struggling with is that there are many records where the manufacturer or model (name) is not filled out. I represent that in the listboxes by setting their rowsource to an iif statement that says if it is null, make it "(No Value)".
The tricky part comes in to the code above. When someone chooses "(No Value)" How do I make the query see that as null or nothing?
Any thoughts? I tried a few variations which is all in this part here:
But whether I do
or
or
I get no results on the summary. If I pick any other value, with or without (No Value) I get the results for those values.
Any help would be greatly appreciated!!!
misscrf
It is never too late to become what you could have been ~ George Eliot
I am using this method to create different report menus, which works great. Users can choose what type of report they want and then go to that report menu. If it is say a menu for Car Manufacturers, they have 2 list boxes. 1 for manufacturers and 1 for car models.
The list boxes are populated by just that field based on the main databse table for the info that has been filled in for all records (ie. some customer records do not have the car manufacturer or model filled out.)
Here is my challenge. I have this set up so that users can choose 1 or more of the values in either of the 2 listboxes and then click to get a subform (visible) with a grid (datasheet) layout that they can take to Excel or hit another button and get a formatted report.
This is the code that I have been working on:
Code:
Private Sub cmdSummary_Click()
Dim Mysql As String
Dim strCriteria As String
strCriteria = "1=1 "
If Me.LstCarMan = "(No Value)" Then
strCriteria = strCriteria & _
" AND isnull(txtCarManufacturer)"
Else
strCriteria = strCriteria & _
BuildIn(Me.LstCarMan, "txtCarManufacturer", "'")
End If
If Me.lstCarName = "(No Value)" Then
strCriteria = strCriteria & _
" AND txtCarName isnull "
Else
strCriteria = strCriteria & _
BuildIn(Me.lstCarName, "txtCarName", "'")
End If
Mysql = "SELECT * FROM qryCarQuery Where "
Mysql = Mysql & strCriteria
Me![frmSubCarQry].Form.RecordSource = Mysql
Me.frmSubCarQry.Visible = True
End Sub
The part I am struggling with is that there are many records where the manufacturer or model (name) is not filled out. I represent that in the listboxes by setting their rowsource to an iif statement that says if it is null, make it "(No Value)".
The tricky part comes in to the code above. When someone chooses "(No Value)" How do I make the query see that as null or nothing?
Any thoughts? I tried a few variations which is all in this part here:
Code:
If Me.LstCarMan = "(No Value)" Then
strCriteria = strCriteria & _
" AND isnull(txtCarManufacturer)"
Else
strCriteria = strCriteria & _
BuildIn(Me.LstCarMan, "txtCarManufacturer", "'")
End If
Code:
strCriteria = strCriteria & _
" AND txtCarManufacturer is null"
Code:
strCriteria = strCriteria & _
" AND txtCarManufacturer isnull"
Code:
strCriteria = strCriteria & _
" AND isnull(txtCarManufacturer)"
Any help would be greatly appreciated!!!
misscrf
It is never too late to become what you could have been ~ George Eliot