PC Review


Reply
Thread Tools Rate Thread

Filter data by using a form and open a report based on this data

 
 
=?Utf-8?B?QWNjZXNzUHJvamVjdA==?=
Guest
Posts: n/a
 
      26th Sep 2007
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
 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      27th Sep 2007
AccessProject wrote:
>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 don't understand why you are messing with the form's
Filter, but from where I sit the rest of the code looks like
it should work. Did you try it? If not, why not? If you
did, what about it didn't do what you want?

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter a Report Using a Form's Filter amr Microsoft Access Reports 3 11th Jan 2010 12:58 AM
How to turn an Access form-based report into a table-based report drewship Microsoft Access Reports 0 17th Jul 2009 12:36 PM
Filter Form, Print Report based on Filter 2Blessed4Stress Microsoft Access Forms 1 2nd Jul 2009 10:50 PM
Filter Report based on forms filter bymarce Microsoft Access Form Coding 2 15th Jul 2008 03:30 PM
Filter report based on filter on form Henrootje Microsoft Access 1 19th Dec 2005 12:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:27 PM.