473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

using a form to filter a report

I would like to make a form that filters a report by Supervisor and by
starting and ending date.
I have the supervisors in a combo box, and that works.
However, I do not know how to code to let the user enter a starting
and ending date and only show the records between those dates.
The code that I have so far does not work for the dates, but I'm
including it anyway so you show me what to change.
Thanks so much! :)

Here is my code (the supervisor combo box works, the start and ending
date text boxes do not):

Option Compare Database
Option Explicit

Private Sub cmdApplyFilter_Click()
Dim strSupervisor As String
Dim strFilter As String
Dim strStart As String
Dim strEnd As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Salary data &
SS#-Current") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for Supervisor field
If IsNull(Me.cboSupervisor.Value) Then
strSupervisor = "Like '*'"
Else
strSupervisor = "='" & Me.cboSupervisor.Value & "'"
End If
' Build criteria string for Starting date field
If IsNull(Me.Start.Value) Then
strStart = "Like '*'"
Else
strStart = "='" & Me.Start.Value & "'"
End If
' Build criteria string for Ending date field'
If IsNull(Me.End.Value) Then
strEnd = "Like '*'"
Else
strEnd = "='" & Me.End.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[supervisor_f] " & strSupervisor & " AND [start_date]
" & strStart & " AND [end_date] " & strEnd
' strFilter = "[supervisor_f] " & strSupervisor
' Apply the filter and switch it on
With Reports![Salary data & SS#-Current]
.Filter = strFilter
.FilterOn = True
End With
End Sub

Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![Salary data & SS#-Current].FilterOn = False
End Sub
Nov 13 '05 #1
3 2886
You are using a string delimiter instead of a date delimiter in
your expressions.

strStart = "=#" & Me.Start.Value & "#"
strEnd = "=#" & Me.End.Value & "#"

The Hash (#) is for dates, the tick (') is for strings.
aj*******@hotmail.com (Afton) wrote in
news:76**************************@posting.google.c om:
I would like to make a form that filters a report by
Supervisor and by starting and ending date.
I have the supervisors in a combo box, and that works.
However, I do not know how to code to let the user enter a
starting and ending date and only show the records between
those dates. The code that I have so far does not work for the
dates, but I'm including it anyway so you show me what to
change. Thanks so much! :)

Here is my code (the supervisor combo box works, the start and
ending date text boxes do not):

Option Compare Database
Option Explicit

Private Sub cmdApplyFilter_Click()
Dim strSupervisor As String
Dim strFilter As String
Dim strStart As String
Dim strEnd As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Salary data &
SS#-Current") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for Supervisor field
If IsNull(Me.cboSupervisor.Value) Then
strSupervisor = "Like '*'"
Else
strSupervisor = "='" & Me.cboSupervisor.Value & "'"
End If
' Build criteria string for Starting date field
If IsNull(Me.Start.Value) Then
strStart = "Like '*'"
Else
strStart = "='" & Me.Start.Value & "'"
End If
' Build criteria string for Ending date field'
If IsNull(Me.End.Value) Then
strEnd = "Like '*'"
Else
strEnd = "='" & Me.End.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[supervisor_f] " & strSupervisor & " AND
[start_date]
" & strStart & " AND [end_date] " & strEnd
' strFilter = "[supervisor_f] " & strSupervisor
' Apply the filter and switch it on
With Reports![Salary data & SS#-Current]
.Filter = strFilter
.FilterOn = True
End With
End Sub

Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![Salary data & SS#-Current].FilterOn = False
End Sub


--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #2
I haven't gone through all of your code. Have you considered using a
query as the record source of your report. Then, in the criteria of
the fields you want to prompt, reference the fields on the form. It
works really well, I use it all the time.

Let me know if you want to learn more.

aj*******@hotmail.com (Afton) wrote in message news:<76**************************@posting.google. com>...
I would like to make a form that filters a report by Supervisor and by
starting and ending date.
I have the supervisors in a combo box, and that works.
However, I do not know how to code to let the user enter a starting
and ending date and only show the records between those dates.
The code that I have so far does not work for the dates, but I'm
including it anyway so you show me what to change.
Thanks so much! :)

Here is my code (the supervisor combo box works, the start and ending
date text boxes do not):

Option Compare Database
Option Explicit

Private Sub cmdApplyFilter_Click()
Dim strSupervisor As String
Dim strFilter As String
Dim strStart As String
Dim strEnd As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Salary data &
SS#-Current") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for Supervisor field
If IsNull(Me.cboSupervisor.Value) Then
strSupervisor = "Like '*'"
Else
strSupervisor = "='" & Me.cboSupervisor.Value & "'"
End If
' Build criteria string for Starting date field
If IsNull(Me.Start.Value) Then
strStart = "Like '*'"
Else
strStart = "='" & Me.Start.Value & "'"
End If
' Build criteria string for Ending date field'
If IsNull(Me.End.Value) Then
strEnd = "Like '*'"
Else
strEnd = "='" & Me.End.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[supervisor_f] " & strSupervisor & " AND [start_date]
" & strStart & " AND [end_date] " & strEnd
' strFilter = "[supervisor_f] " & strSupervisor
' Apply the filter and switch it on
With Reports![Salary data & SS#-Current]
.Filter = strFilter
.FilterOn = True
End With
End Sub

Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![Salary data & SS#-Current].FilterOn = False
End Sub

Nov 13 '05 #3
aj*******@hotmail.com (Afton) wrote in message news:<76**************************@posting.google. com>...
I would like to make a form that filters a report by Supervisor and by
starting and ending date.
I have the supervisors in a combo box, and that works.
However, I do not know how to code to let the user enter a starting
and ending date and only show the records between those dates.
The code that I have so far does not work for the dates, but I'm
including it anyway so you show me what to change.
Thanks so much! :)


Build a valid WHERE clause (without the keyword WHERE) and then just
pass that in the filter of the report...

dim strFilter as string
Const cQUOTE As String = "'"

strFilter="[Supervisor]=" & cQUOTE & Me.cboSupervisor & cQUOTE
strFilter = strFilter & " AND [SomeDate] BETWEEN #" & Me.txtStartDate
& "# AND #" & Me.txtEndDate & "#"

Public Sub OpenAndPrintReport(ByVal strReport As String, ByVal
strFilter As String)
DoCmd.OpenReport strReport, acViewPreview, , strFilter,
acWindowNormal
End Sub
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
1
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
1
by: Chasing Gates | last post by:
I have created a database that brings in a new table weekly. I then made a separate query for each sales rep and a separate report for each rep. (The reports are all identical but call different...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
8
by: | last post by:
hi, i have a form on which a user can choose specific criteria such as dates etc, in order to filter the report that is called from the form. i do this by using the Where section of the...
2
by: KashMarsh | last post by:
Access 2003 I need to have a user filter records on a linked, continuous form and then I want to run various reports/queries from this recordset the user created. I only need to see the PK...
3
by: emgallagher | last post by:
I have a form which lists studies. People can filter the form based on details about the study, such as the study type. Currently users filter via the right click method. I would like to be...
1
by: Cara Murphy | last post by:
Hi There! Hoping you are able to help me with a filtering scenario: I have created a pop up form (Filter) to filter a report (Open Issues), which currently has a number of combo boxes which...
2
by: phill86 | last post by:
Hi, I am filtering a report using the form filter with the following code DoCmd.OpenReport "report1", acViewReport, , Me.filter Which works fine untill I filter the form on one of the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.