chanman525
IS-IT--Management
I found a snippet of code from this forum but can not recall who placed the link. At any rate it was a sample DB to use multi select list boxes to provide criteria to a query, and the end result populated a form with matching criteria.(Form is based off of query) The code works great except when it comes to handling dates, and I can not figure how to manipulate it.
The problem is the list box is sending the date selected as a string (ex: "6/11/2007") to the function and the query is looking for a match of a date (ex: 6/11/2007). Since they don't match it displays nothing.
Here is the sql for the query:
SELECT TblProject.*
FROM TblProject
WHERE (((IsSelectedVar("FrmReportCriteria","lboDateAdded",[DateAdded]))=-1));
Here is the function that is called in the query:
Function IsSelectedVar(strFormName As String, strListBoxName As String, varValue As Variant) As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
End Function
The list box is simply populated by this query:
SELECT TblProject.DateAdded
FROM TblProject
GROUP BY TblProject.DateAdded;
The dateadded field is simply a short date field and is populated with a default value of Date().
If some one has any ideas on how to change the way the listbox is passing the date to the function that would be great.
Thanks for your time and brain power!
The problem is the list box is sending the date selected as a string (ex: "6/11/2007") to the function and the query is looking for a match of a date (ex: 6/11/2007). Since they don't match it displays nothing.
Here is the sql for the query:
SELECT TblProject.*
FROM TblProject
WHERE (((IsSelectedVar("FrmReportCriteria","lboDateAdded",[DateAdded]))=-1));
Here is the function that is called in the query:
Function IsSelectedVar(strFormName As String, strListBoxName As String, varValue As Variant) As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
End Function
The list box is simply populated by this query:
SELECT TblProject.DateAdded
FROM TblProject
GROUP BY TblProject.DateAdded;
The dateadded field is simply a short date field and is populated with a default value of Date().
If some one has any ideas on how to change the way the listbox is passing the date to the function that would be great.
Thanks for your time and brain power!