Print via an IF THEN command

K

Katrina

I have a command that looks like...

Function PrintRep()
Dim objReport As Object
Dim objreportname As Variant

For Each objReport In CurrentProject.AllReports
If objReport.NAME = "Operators*" Then
DoCmd.OpenReport objReport.NAME, acPrint
ElseIf objReport.NAME = "Systems*" Then
DoCmd.OpenReport objReport.NAME, acPrint
End If
Next objReport

End Function

However, VBA doesn't seem to like the objreport.name = line

In case it's not obvious, I'm trying to print all reports
that start with "operators" or "Systems"
Any ideas?

Thanks
 
D

Dirk Goldgar

Katrina said:
I have a command that looks like...

Function PrintRep()
Dim objReport As Object
Dim objreportname As Variant

For Each objReport In CurrentProject.AllReports
If objReport.NAME = "Operators*" Then
DoCmd.OpenReport objReport.NAME, acPrint
ElseIf objReport.NAME = "Systems*" Then
DoCmd.OpenReport objReport.NAME, acPrint
End If
Next objReport

End Function

However, VBA doesn't seem to like the objreport.name = line

In case it's not obvious, I'm trying to print all reports
that start with "operators" or "Systems"
Any ideas?

How about ...

Function PrintRep()

Dim aoReport As AccessObject

For Each aoReport In CurrentProject.AllReports
If aoReport.Name Like "Operators*" Then
DoCmd.OpenReport aoReport.Name, acPrint
ElseIf aoReport.Name Like "Systems*" Then
DoCmd.OpenReport aoReport.Name, acPrint
End If
Next aoReport

End Function
 
S

SteveS

Maybe this will work for you

=====
Dim objReport As Object

For Each objReport In CurrentProject.AllReports
If Left(objReport.Name, 9) = "Operators" Then
DoCmd.OpenReport objReport.Name
ElseIf Left(objReport.Name, 7) = "Systems" Then
DoCmd.OpenReport objReport.Name
End If
Next objReport
=====

In A2K, there is no acPrint option. If the view option is
acViewNormal, the report prints immediately. If you leave
this argument blank, the default constant (acViewNormal)
is assumed.


HTH

Steve
 
D

Dirk Goldgar

Dirk Goldgar said:
How about ...

Function PrintRep()

Dim aoReport As AccessObject

For Each aoReport In CurrentProject.AllReports
If aoReport.Name Like "Operators*" Then
DoCmd.OpenReport aoReport.Name, acPrint
ElseIf aoReport.Name Like "Systems*" Then
DoCmd.OpenReport aoReport.Name, acPrint
End If
Next aoReport

End Function

SteveS is right, there's no "acPrint" constant -- I wasn't thinking.
Use acViewNormal or acNormal, or just leave it off altogether.
 

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