Date Range in VBA

rachel_harder

Registered User.
Local time
Today, 14:14
Joined
Feb 4, 2015
Messages
13
Hello,
I have a form that has several drop down menus on it. I use the form to filter the database to only the options that are put into the drop down windows. I have it set up so that every window does not need to be filled in for the filter to work. Now I am trying to figure out how to put the option of a date range on my form as well. The code that I am using to make everything up to the date range work is.
Code:
Private Sub Search_Button_Click()
DoCmd.Close acForm, "Admin_CompletedPartSearch"
str_Form = "Admin_CompletedPartSearch"
str_Filter = "(1=1)"
If (IsNull(Me.Division) = False) Then str_Filter = str_Filter & " AND ([Division] ='" & Me.Division & "')"
If (IsNull(Me.Open_Closed) = False) Then str_Filter = str_Filter & " AND ([Open_Closed] ='" & Me.Open_Closed & "')"
If (IsNull(Me.QC_Inspector) = False) Then str_Filter = str_Filter & " AND ([QC_Inspector] ='" & Me.QC_Inspector & "')"
If (IsNull(Me.Fleet) = False) Then str_Filter = str_Filter & " AND ([Fleet] ='" & Me.Fleet & "')"
If (IsNull(Me.Area) = False) Then str_Filter = str_Filter & " AND ([Area] ='" & Me.Area & "')"
If (IsNull(Me.Part_Number) = False) Then str_Filter = str_Filter & " AND ([Part_Number] ='" & Me.Part_Number & "')"
If (IsNull(Me.Part_Number) = False) Then str_Filter = str_Filter & " OR ([Part_Number2] ='" & Me.Part_Number & "')"
If (IsNull(Me.Part_Number) = False) Then str_Filter = str_Filter & " OR ([Part_Number3] ='" & Me.Part_Number & "')"
If (IsNull(Me.Part_Number) = False) Then str_Filter = str_Filter & " OR ([Part_Number4] ='" & Me.Part_Number & "')"
DoCmd.OpenForm str_Form, acViewNormal, acEdit
DoCmd.ApplyFilter , str_Filter
DoCmd.Close acForm, Me.Name
End Sub
I can't figure out what I would need to do to make a date range also fit into this code but not to be required. Thanks for any help.
 
What have you tried? Just follow what you have for the the other inputs--test if its null, if not update strFilter.

Also, you have incorrectly configured the Me.Part_Number ones. First, there's no need to test it repeatedly. Second, you need to enclose that entire section (starting after the AND) in parenthesis:

Code:
"AND ((Part1) OR (Part2) OR (Part3) OR (Part4))"
 

Users who are viewing this thread

Back
Top Bottom