Parameters for a report

G

gregboyer

I'm a brand new Access user, and trying to set up a form to collect
parameters for a report that I want to run. I've been going through
the online help for Access 2007, and have followed all of the steps as
best as I can. It told me to create a module to check whether a form
is already open, and to paste the code into the Visual Basic editor. I
can get the form to come up and accept the parameters, but when I click
"Ok," I get an error that says,

"Run Time Error 2467. The expression you entered refers to an object
that is closed or doesn't exist."

Here's the code for the module I was instructed to create.

Function IsLoaded(ByVal strFormName As String) As Boolean
Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)

If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If
End Function

Any idea what step or what it is that I'm missing?

Thanks!
 
G

gregboyer

Sorry about the post, looks like I got that particular issue taken care
of.

I do, however, have another question. How do I get the Report to only
display the data between the dates that were entered on the form?
 
M

Marshall Barton

I do, however, have another question. How do I get the Report to only
display the data between the dates that were entered on the form?


You should be using a button on the form to run the report.
In this case, the report's record source query should not
use parameters. Instead, you should use the OpenReport
method's WhereCondition argument to filter the data. Look
at the button's wizard generated Click event procedure and
modify it along these lines:

stCriteria = "yourdatefield Between " _
& Format(txtStartDate, "\#m\/d\/yyyy\#") & " AND " _
& Format(txtStartDate, "\#m\/d\/yyyy\#")
DoCmd.OpenReport stDocName, acPreview, , stCriteria
 
M

martin.dion

If you open your report using code, you use
docmd.openReport ReportName, acViewPreview (or acViewNormal for direct
printing), filterName, datefield>=#beginDate# AND datefield<=#endDate#

datefield is the date in your table

begindate is the beginning date

enddate is the ending date
 
G

gregboyer

Right now, the way my forms and such are set up is that a button is
clicked on the Data Entry form, which runs an "OpenReport" for my
pre-formatted report. The report has an "OnOpen" command to bring up a
different form, which prompts for dates. Once the dates are entered on
that form, I'm having trouble getting it to filter the data on the
report; right now it's showing all entries in my table. The format is
correct, of course, but I haven't been able to successfully narrow down
the date range of the data.
 
M

martdi

You could use two input boxes on your button before calling the open of
the report.

private sub reportbutton_click()

dateBegin = inputbox("date1")
dateEnd = inputbox("date2")

docmd.openreport("reportName", acViewPreview, , datefield > date1
and datefield < date2)

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