Hello guys,
I'd first like to thank everyone for all their informative posts, I have only been working with access for a couple days but this fourm has already been a life-saver for me.
I'm usually pretty good at figuring stuff out, backwards engineering peoples examples, but I'm having difficulty with this one, I've seen tons of 'Date ranges' using queries and reports all over this fourm but none seem to be what I'm looking for.
The Main part of my example came from Gromit. It’s a "Search Form" using unbound and combo text boxes for input queries to filter subform results.
What I want to do is be able to specify a specific date, or a range of dates to filter the results with. Like a one week span of 10/13/2008-10/17/2008.
I'm sure there's a way, I just can't seem to grasp what I need to do.
IF anyone could take a look at my example and help me out it would be much appreciated.
I Hope its just a matter of changing the syntax around so that it knows it’s dates that I’m trying to compare, I just don’t know how to do it.
Looking at similar posts on here I Tried changing the date format to a couple different things. Like below
But all that does it stop the program from running..
Please somebody help me
This is my first database I'm making to track all the product we have going through our quality facility, I has a Main input, for our inspectors, A disposition form for our engineers to disposition any non comforming parts, and then the search form, to filter out the unwanted results.
I'd first like to thank everyone for all their informative posts, I have only been working with access for a couple days but this fourm has already been a life-saver for me.
I'm usually pretty good at figuring stuff out, backwards engineering peoples examples, but I'm having difficulty with this one, I've seen tons of 'Date ranges' using queries and reports all over this fourm but none seem to be what I'm looking for.
The Main part of my example came from Gromit. It’s a "Search Form" using unbound and combo text boxes for input queries to filter subform results.
What I want to do is be able to specify a specific date, or a range of dates to filter the results with. Like a one week span of 10/13/2008-10/17/2008.
I'm sure there's a way, I just can't seem to grasp what I need to do.
IF anyone could take a look at my example and help me out it would be much appreciated.
Code:
Private Sub btnClear_Click()
Dim intIndex As Integer
' Clear all search items
Me.txtSWO = ""
Me.txtPART = ""
Me.txtondate = ""
Me.txtStartDate = ""
Me.txtEndDate = ""
Me.cmbDisposition = 0
Me.cmbInspector = 0
Me.cmbNonConforming = 0
End Sub
Private Sub btnSearch_Click()
' Update the record source
If BuildFilter = "" Then
Me.qrydatasub.Form.RecordSource = "SELECT * FROM qrydata " & BuildFilter
Else
Me.qrydatasub.Form.RecordSource = "SELECT * FROM qrydata WHERE " & BuildFilter
End If
End Sub
Private Sub Command21_Click()
End Sub
Private Sub Form_Load()
' Clear the search form
btnClear_Click
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varColor As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
varColor = Null ' Subfilter used for colors
' Check for SWO Numbers
If Me.txtSWO > "" Then
varWhere = varWhere & "[SWO Number] LIKE """ & Me.txtSWO & "*"" AND "
End If
' Check for Part Number
If Me.txtPART > "" Then
varWhere = varWhere & "[Part Number] LIKE """ & Me.txtPART & "*"" AND "
End If
' Check for End Date
If Me.txtStartDate = "" And Me.txtEndDate = "" Then
If Me.txtEndDate > "" Then
varWhere = varWhere & "[Date] <" & Me.txtondate & " AND "
End If
End If
' Check for Start date
If Me.txtStartDate > "" Then
varWhere = varWhere & "[Date] >" & Me.txtStartDate & " AND "
End If
' Check for End Date
If Me.txtEndDate > "" Then
varWhere = varWhere & "[Date] <" & Me.txtEndDate & " AND "
End If
' Check for Dispostion
If Me.cmbDisposition > 0 Then
varWhere = varWhere & "[DispositionID] = " & Me.cmbDisposition & " AND "
End If
' Check for Inspector
If Me.cmbInspector > 0 Then
varWhere = varWhere & "[InspectorID] = " & Me.cmbInspector & " AND "
End If
' Check for Non Conforming
If Me.cmbNonConforming > 0 Then
varWhere = varWhere & "[NonConformingID] = " & Me.cmbNonConforming & " AND "
End If
' Test to see if we have subfilter for colors...
If IsNull(varColor) Then
' do nothing
Else
' strip off last "OR" in the filter
If Right(varColor, 4) = " OR " Then
varColor = Left(varColor, Len(varColor) - 4)
End If
' Add some parentheses around the subfilter
varWhere = varWhere & "( " & varColor & " )"
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
I Hope its just a matter of changing the syntax around so that it knows it’s dates that I’m trying to compare, I just don’t know how to do it.
Looking at similar posts on here I Tried changing the date format to a couple different things. Like below
Code:
' Check for Start date
If Me.txtStartDate > "" Then
varWhere = varWhere & "[Date] >" "#" & Me.txtStartDate & "#"" AND "
End If
' Check for End Date
If Me.txtEndDate > "" Then
varWhere = varWhere & "[Date] <" "#" & Me.txtEndDate & "#"" AND "
End If
But all that does it stop the program from running..
Please somebody help me
This is my first database I'm making to track all the product we have going through our quality facility, I has a Main input, for our inspectors, A disposition form for our engineers to disposition any non comforming parts, and then the search form, to filter out the unwanted results.