A
AccessProject
Hello,
I created a form with 3 criterias: location, date to and from and course
name. I have a reset button and a filter/search button. I want to open a
report called "Sign-in" based on any of these criterias.
Onclick I have filter all 3 criterias but I don't know how to open a report.
I used the codes from previous posting:
Private Sub cmdFilter_Click()
....
'Text field example. Use quotes around the value in the string.
If Not IsNull(Me.txtFilterLocation) Then
strWhere = strWhere & "([Location] = """ & Me.txtFilterLocation &
""") AND "
End If
'Number field example. Do not add the extra quotes.
If Not IsNull(Me.cboFilterTrainingName) Then
strWhere = strWhere & "([TrainingName] = " &
Me.cboFilterTrainingName & ") AND "
End If
'Date field example. Use the format string to add the # delimiters and
get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([TrainingDate] >= " &
Format(Me.txtStartDate, conJetDate) & ") AND "
End If
'Another date field example. Use "less than the next day" since this
field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([TrainingDate] < " & Format(Me.txtEndDate +
1, conJetDate) & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
Debug.Print strWhere
Me.Filter = strWhere
Me.FilterOn = True
DoCmd.OpenReport "Sign-in Sheet", acViewPreview, , Me.Filter
End If
End Sub
I created a form with 3 criterias: location, date to and from and course
name. I have a reset button and a filter/search button. I want to open a
report called "Sign-in" based on any of these criterias.
Onclick I have filter all 3 criterias but I don't know how to open a report.
I used the codes from previous posting:
Private Sub cmdFilter_Click()
....
'Text field example. Use quotes around the value in the string.
If Not IsNull(Me.txtFilterLocation) Then
strWhere = strWhere & "([Location] = """ & Me.txtFilterLocation &
""") AND "
End If
'Number field example. Do not add the extra quotes.
If Not IsNull(Me.cboFilterTrainingName) Then
strWhere = strWhere & "([TrainingName] = " &
Me.cboFilterTrainingName & ") AND "
End If
'Date field example. Use the format string to add the # delimiters and
get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([TrainingDate] >= " &
Format(Me.txtStartDate, conJetDate) & ") AND "
End If
'Another date field example. Use "less than the next day" since this
field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([TrainingDate] < " & Format(Me.txtEndDate +
1, conJetDate) & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
Debug.Print strWhere
Me.Filter = strWhere
Me.FilterOn = True
DoCmd.OpenReport "Sign-in Sheet", acViewPreview, , Me.Filter
End If
End Sub