Access Filter Specific Date in Access.

Joined
Apr 6, 2010
Messages
2
Reaction score
0
Hey,

I have a form which has several fields. I have created another section on the same form for filtering information. I have an unbound textbox called txtUnloaded that when operating correctly will filter out all records who field "Unloaded" has the specific Date. I cannot get the date one to work corretly for the specific date. I have another filter for between dates but the txtUnloaded date does not work. any help would be appreciated. Here is the code I have.


Private Sub Command150_Click()
Dim strForm As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strForm = "InfoInput"
strField = "Data_Entry"

If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
strWhere = strField & " < " & Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no End.
strWhere = strField & " > " & Format(Me.txtStartDate, conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If

If Not IsNull(Me.[txtPartNum]) Then
If strWhere <> "" Then
strWhere = "(" & strWhere & ") AND (PartNumber = """ & Me.[txtPartNum] & """)"
Else
strWhere = "PartNumber = """ & Me.[txtPartNum] & """"
End If
End If

If Not IsNull(Me.[txtWrkOrder]) Then
If strWhere <> "" Then
strWhere = "(" & strWhere & ") AND (WorkOrderNumber = """ & Me.[txtWrkOrder] & """)"
Else
strWhere = "WorkOrderNumber = """ & Me.[txtWrkOrder] & """"
End If
End If

If Not IsNull(Me.[txtPan]) Then
If strWhere <> "" Then
strWhere = "(" & strWhere & ") AND (PanNumber = """ & Me.[txtPan] & """)"
Else
strWhere = "PanNumber = """ & Me.[txtPan] & """"
End If
End If

If Not IsNull(Me.[txtMachine]) Then
If strWhere <> "" Then
strWhere = "(" & strWhere & ") AND (MachineNumber = """ & Me.[txtMachine] & """)"
Else
strWhere = "MachineNumber = """ & Me.[txtMachine] & """"
End If
End If
If Not IsNull(Me.[txtUnloaded]) Then
If strWhere <> "" Then
strWhere = "(" & strWhere & ") AND (Unloaded = """ & Me.[txtUnloaded] & """)"
Else
strWhere = "Unloaded = """" & Me.[txtUnload] & """""
End If
End If

If Not IsNull(Me.[txtCycleTime]) Then
If strWhere <> "" Then
strWhere = "(" & strWhere & ") AND (CycleTime = """ & Me.[txtCycleTime] & """)"
Else
strWhere = "CycleTime = """ & Me.[txtCycleTime] & """"
End If
End If
If strWhere <> "" Then
Me.Filter = strWhere
Me.FilterOn = True

Else
Me.FilterOn = False
End If

If [CurrentRecord] = 0 Then
DoCmd.RunCommand acCmdRemoveFilterSort
MsgBox "No records were found within your criteria."
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top