Report to PDF

G

Guest

I have PDF writer 6.0 and am saving(printing) my reports to pdf by OpenReport
macro. I have the default printer set to my pdf. This is working fine.
Each report is for different customers.
How can I automatically save(print) the report to pdf with [CustomerName] as
the file name?
 
G

Guest

Hi Marco,

Try setting the report's caption using VBA code. I think that will work.
Here is an example that I use for outputting named Snapshot files (ie.
CaptionValue.snp). In this case strEquipID is a field in the report's
recordsource.

Private Sub Report_Activate()
On Error GoTo ProcError

Me.Caption = strServiceRequested _
& " Request for " & strEquipID
DoCmd.Maximize

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Error in
Report_Activate event procedure..."
Resume ExitProc
End Sub



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
G

Guest

Tom,

Thank you for your reply.
I am not at all familiar with VBA codes.
Do I need to convert my macro to VBA and add the below?
Thankyou

Tom Wickerath said:
Hi Marco,

Try setting the report's caption using VBA code. I think that will work.
Here is an example that I use for outputting named Snapshot files (ie.
CaptionValue.snp). In this case strEquipID is a field in the report's
recordsource.

Private Sub Report_Activate()
On Error GoTo ProcError

Me.Caption = strServiceRequested _
& " Request for " & strEquipID
DoCmd.Maximize

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Error in
Report_Activate event procedure..."
Resume ExitProc
End Sub



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

MarcoR said:
I have PDF writer 6.0 and am saving(printing) my reports to pdf by OpenReport
macro. I have the default printer set to my pdf. This is working fine.
Each report is for different customers.
How can I automatically save(print) the report to pdf with [CustomerName] as
the file name?
 
G

Guest

Hi Marco,
Do I need to convert my macro to VBA and add the below?
No. Leave your macro as it is for the present time.

Open your report in design view. Then click on View > Code. You should see a
module open. At the very minimum, it should include two lines of code:

Option Compare Database
Option Explicit

If you are missing the second line of code shown above, then add it
manually. Then click on Tools > Options while in the VBA Editor, select the
General tab, and place a check in "Require Variable Declaration". I also
advise clearing the check in the first option, which reads "Auto Syntax
Check". I call that the carpel-tunnel option, because it just produces an
extra error dialog anytime you have an error in the syntax of your code. It
is simply not needed, because syntax errors will cause the code to light up
red, anyways. More details here:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions

Copy the code shown below, and paste it into your new code module for the
report(s) in question. I adjusted the code slightly, so that it sets the
caption to [CustomerName], as you indicated in your initial posting. This
field must be available to the report, or else you will get a compile error.

I also added a Report_Close event procedure, which reverses the maximize
step in the activate procedure. If you always run your application maximized,
then you can delete the DoCmd.Maximize line, and skip adding the Report_Close
procedure.


Private Sub Report_Activate()
On Error GoTo ProcError

Me.Caption = Me.CustomerName
DoCmd.Maximize

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Error in
Report_Activate event procedure..."
Resume ExitProc
End Sub

Private Sub Report_Close()
On Error GoTo ProcError

DoCmd.Restore

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Report_Close..."
Resume ExitProc
End Sub



After adding these two procedures, click on Debug > Compile ProjectName,
where ProjectName is the name of your VBA project (usually the same as the
name of the database, unless you specifically change it). Hopefully, your
code will compile without any errors. If you do get a compile error, try to
identify the cause and correct it. If the menu item becomes "greyed" out,
this means that your code compiled without any problems.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
G

Guest

Hi Marco,
Do I need to convert my macro to VBA and add the below?
No. Leave your macro as it is for the present time.

Open your report in design view. Then click on View > Code. You should see a
module open. At the very minimum, it should include two lines of code:

Option Compare Database
Option Explicit

If you are missing the second line of code shown above, then add it
manually. Then click on Tools > Options while in the VBA Editor, select the
General tab, and place a check in "Require Variable Declaration". I also
advise clearing the check in the first option, which reads "Auto Syntax
Check". I call that the carpel-tunnel option, because it just produces an
extra error dialog anytime you have an error in the syntax of your code. It
is simply not needed, because syntax errors will cause the code to light up
red, anyways. More details here:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions

Copy the code shown below, and paste it into your new code module for the
report(s) in question. I adjusted the code slightly, so that it sets the
caption to [CustomerName], as you indicated in your initial posting. This
field must be available to the report, or else you will get a compile error.

I also added a Report_Close event procedure, which reverses the maximize
step in the activate procedure. If you always run your application maximized,
then you can delete the DoCmd.Maximize line, and skip adding the Report_Close
procedure.


Private Sub Report_Activate()
On Error GoTo ProcError

Me.Caption = Me.CustomerName
DoCmd.Maximize

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Error in
Report_Activate event procedure..."
Resume ExitProc
End Sub

Private Sub Report_Close()
On Error GoTo ProcError

DoCmd.Restore

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Report_Close..."
Resume ExitProc
End Sub



After adding these two procedures, click on Debug > Compile ProjectName,
where ProjectName is the name of your VBA project (usually the same as the
name of the database, unless you specifically change it). Hopefully, your
code will compile without any errors. If you do get a compile error, try to
identify the cause and correct it. If the menu item becomes "greyed" out,
this means that your code compiled without any problems.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
G

Guest

Hi Marco,

I had a detailed answer all prepared, and then I lost the *&^%$# thing when
I clicked on the Post button (Thanks Microsoft for such a wonderful web
portal!).

It's really late for me right now. Let me try again tomorrow evening.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________


MarcoR said:
Tom,

Thank you for your reply.
I am not at all familiar with VBA codes.
Do I need to convert my macro to VBA and add the below?
Thankyou

Tom Wickerath said:
Hi Marco,

Try setting the report's caption using VBA code. I think that will work.
Here is an example that I use for outputting named Snapshot files (ie.
CaptionValue.snp). In this case strEquipID is a field in the report's
recordsource.

Private Sub Report_Activate()
On Error GoTo ProcError

Me.Caption = strServiceRequested _
& " Request for " & strEquipID
DoCmd.Maximize

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Error in
Report_Activate event procedure..."
Resume ExitProc
End Sub



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

MarcoR said:
I have PDF writer 6.0 and am saving(printing) my reports to pdf by OpenReport
macro. I have the default printer set to my pdf. This is working fine.
Each report is for different customers.
How can I automatically save(print) the report to pdf with [CustomerName] as
the file name?
 
G

Guest

Tom,

Thank you so much for your detailed instruction.
I did exactly as your instruction, Debug > Compile ProjectName at the end
and the menu item greyed out.
Unfortunately, when I ran my macro to print to pdf, it was the same result
as before I added the code.
"Save PDF file as" screen pops up, and I need to enter a file name to be
saved to.
Any suggestions?


Tom Wickerath said:
Hi Marco,
Do I need to convert my macro to VBA and add the below?
No. Leave your macro as it is for the present time.

Open your report in design view. Then click on View > Code. You should see a
module open. At the very minimum, it should include two lines of code:

Option Compare Database
Option Explicit

If you are missing the second line of code shown above, then add it
manually. Then click on Tools > Options while in the VBA Editor, select the
General tab, and place a check in "Require Variable Declaration". I also
advise clearing the check in the first option, which reads "Auto Syntax
Check". I call that the carpel-tunnel option, because it just produces an
extra error dialog anytime you have an error in the syntax of your code. It
is simply not needed, because syntax errors will cause the code to light up
red, anyways. More details here:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions

Copy the code shown below, and paste it into your new code module for the
report(s) in question. I adjusted the code slightly, so that it sets the
caption to [CustomerName], as you indicated in your initial posting. This
field must be available to the report, or else you will get a compile error.

I also added a Report_Close event procedure, which reverses the maximize
step in the activate procedure. If you always run your application maximized,
then you can delete the DoCmd.Maximize line, and skip adding the Report_Close
procedure.


Private Sub Report_Activate()
On Error GoTo ProcError

Me.Caption = Me.CustomerName
DoCmd.Maximize

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "Error in
Report_Activate event procedure..."
Resume ExitProc
End Sub

Private Sub Report_Close()
On Error GoTo ProcError

DoCmd.Restore

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Report_Close..."
Resume ExitProc
End Sub



After adding these two procedures, click on Debug > Compile ProjectName,
where ProjectName is the name of your VBA project (usually the same as the
name of the database, unless you specifically change it). Hopefully, your
code will compile without any errors. If you do get a compile error, try to
identify the cause and correct it. If the menu item becomes "greyed" out,
this means that your code compiled without any problems.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

MarcoR said:
Tom,

Thank you for your reply.
I am not at all familiar with VBA codes.
Do I need to convert my macro to VBA and add the below?
Thankyou
 
G

Guest

Any suggestions?

No, other than have you tried using Stephen Leban's report to .PDF code? I
know you indicated that you had PDF writer 6.0, but perhaps you can use this
freebie method instead:

http://www.lebans.com/reporttopdf.htm

Also, see this previous thread, and in particular, message # 5. A person
who posted last year, in August, 2005, indicated that my caption trick worked
for him. I'm not sure why you are having trouble, assuming that Veli reported
an accurate result:

http://groups.google.com/group/micr..._frm/thread/52928f4e42d34659/6da0a47365ed5a54


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 

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