Filtering a List Box using a date rage and combo selection.

bakkouz

Registered User.
Local time
Today, 14:23
Joined
Jan 16, 2011
Messages
48
Hi,
I am using this code to filter a List Box based on a Date range and a Combo Box selection:

Code:
Private Sub Combo139_AfterUpdate()
Dim StrgSQL As String
      StrgSQL = "SELECT  [User Name], [Date Of Request], [Description of Problem], Status, Sub_Job FROM QRY_SearchAll " & _
                "WHERE [Date of request] BETWEEN #" & CDate(Me.txtStartDate) & _
                "# AND #" & CDate(Me.txtEndDate) & "#;"
StrgSQL = StrgSQL & " WHERE Sub_Job = Combo139"
Me.SearchResults.RowSource = StrgSQL
Me.SearchResults.Requery
End Sub
However, It is not working. when I click the Combo box the List Box comes up blank. what am I doing wrong?
 
Last edited:
Untested, but maybe something like:
Code:
Private Sub Combo139_AfterUpdate()
Dim StrgSQL As String
      StrgSQL = "SELECT  [User Name], [Date Of Request], [Description of Problem], Status, Sub_Job FROM QRY_SearchAll " & _
                "WHERE [Date of request] BETWEEN #" & CDate(Me.txtStartDate) & _
                "# AND #" & CDate(Me.txtEndDate) & "# AND Sub_Job = " & Me.Combo139

Me.SearchResults.RowSource = StrgSQL
Me.SearchResults.Requery
End Sub
 
Bob,
It did not work, after I click on the combo box, it prompts me to enter a value corresponding to the same option I'm selecting from the combo box.
 
What type of field is "Sub_Job" and what type of value is held in the bound column of the combo box. If it is not numeric, you may need to enclose the value returned by "Me.Combo139" with single quotes:
AND Sub_Job = '" & Me.Combo139 & "'"
 
Hey Bob,
yes indeed Sub_Job is text not numeric, and it is technically working now, expect strangely it is now displaying incorrect results! ie: sometimes it displays results that are out of the date range, sometimes it doesn't display results that are within the date range.
What could be the cause of this?
 
Hey Bob,
yes indeed Sub_Job is text not numeric, and it is technically working now, expect strangely it is now displaying incorrect results! ie: sometimes it displays results that are out of the date range, sometimes it doesn't display results that are within the date range.
What could be the cause of this?
Not sure :confused:. What date format do you use in your part of the world. dd/mm/yyyy or mm/dd/yyyy.
 
its dd/mm/yyyy. and I've set the date format for the [Date Of Request] field and the date range text boxes accordingly. would you like to me attach a sample?
 
Bob, You are right, that was it, Thanks alot.
although i suspect this will cause some confusion for the users. I'll see what I can do about it.
Thanks again.
 
Bob, You are right, that was it, Thanks alot.
although i suspect this will cause some confusion for the users. I'll see what I can do about it.
Thanks again.
Why should it confuse the users.
 
well because when entering the date they are accustomed to dd/mm/yyyy and the form only seems to work with the mm/dd/yyyy format so until they get used to it I suspect they'll be some confusion :)
 
well because when entering the date they are accustomed to dd/mm/yyyy and the form only seems to work with the mm/dd/yyyy format so until they get used to it I suspect they'll be some confusion :)
Let them continue to enter dates in the format that they expect to use (dd/mm/yyyy) and adjust your code to handle it. Perhaps something like:
Code:
Combo139_AfterUpdate()
Dim StrgSQL As String
      StrgSQL = "SELECT  [User Name], [Date Of Request], [Description of Problem], Status, Sub_Job FROM QRY_SearchAll " & _
                "WHERE [Date of request] BETWEEN #" & CDate(Format(Me.txtStartDate,"mm\/dd\/yyyy")) & _
                "# AND #" & CDate(Format(Me.txtEndDate,"mm\/dd\/yyyy")) & "# AND Sub_Job = " & Me.Combo139

Me.SearchResults.RowSource = StrgSQL
Me.SearchResults.Requery
End Sub
 
This worked like a charm! You are fantastic! thanks a ton! :)
 

Users who are viewing this thread

Back
Top Bottom