By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,042 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,042 IT Pros & Developers. It's quick & easy.

Trying to open a saved report with a filter specification (A97)

P: n/a
MLH
Private Sub Command0_Click()
Dim MyReport As Report
MyReport.Name = "rptStateOfAffairs"
MyReport.Filter = "ClusterName = 'Auto Company, Inc'"
Me.FilterOn = True
DoCmd.OpenReport MyReport.Name
End Sub

Above code fails - Access doesn't like the 4th line. What change need
I make to open the report with desired filter spec?
Jun 19 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
MLH wrote:
Private Sub Command0_Click()
Dim MyReport As Report
MyReport.Name = "rptStateOfAffairs"
MyReport.Filter = "ClusterName = 'Auto Company, Inc'"
Me.FilterOn = True
DoCmd.OpenReport MyReport.Name
End Sub

Above code fails - Access doesn't like the 4th line. What change need
I make to open the report with desired filter spec?
Why not
Dim MyReport As String
MyReport = "rptStateOfAffairs"
Docmd.OpenReport MyReport,,,"ClusterName = 'Auto Company, Inc'"

Btw, you are setting MyReport's filter, through the report isn't open
and then you are turning on Me's filteron to true, not the reports.

Also, you never set MyReport to an object.

So there are a variety of things that could go wrong.

Jun 19 '07 #2

P: n/a
On Mon, 18 Jun 2007 21:00:47 -0400, MLH wrote:
Private Sub Command0_Click()
Dim MyReport As Report
MyReport.Name = "rptStateOfAffairs"
MyReport.Filter = "ClusterName = 'Auto Company, Inc'"
Me.FilterOn = True
DoCmd.OpenReport MyReport.Name
End Sub

Above code fails - Access doesn't like the 4th line. What change need
I make to open the report with desired filter spec?
You wish to hard code the filter into this code?

Private Sub Command0_Click()
Dim stDocName as String
Dim stWhere as string
stDocName = "rptStateOfaffairs"
stWhere = "[ClusterName] = 'Auto Company, Inc'"

DoCmd.OpenReport stDocName, acViewPreview, , stWhere
End Sub.

Of course you can simplify the above to:

Private Sub Command0_Click()
DoCmd.OpenReport "rptStateOfAffairs", acViewPreview, , "[ClusterName]
= 'Auto Company, Inc'"
End Sub

Look up the OpenReport method in VBA help for the necessary arguments.
Cbange acViewPreview to acViewNormal to print without previewing.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Jun 19 '07 #3

P: n/a
MLH
What was I thinkin'?
Thanks, Salad.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
Why not
Dim MyReport As String
MyReport = "rptStateOfAffairs"
Docmd.OpenReport MyReport,,,"ClusterName = 'Auto Company, Inc'"

Btw, you are setting MyReport's filter, through the report isn't open
and then you are turning on Me's filteron to true, not the reports.

Also, you never set MyReport to an object.

So there are a variety of things that could go wrong.
Jun 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.