Obtain report's caption from report's name in code

B

BlueWolverine

Hello,
MS ACCESS 2003 on XP PRO.

I want to use the caption from a report as it's filename when using a print
to pdf module I have from lebans.com

So what I want to do is something like this.

str_RptName = Forms!my_Form!my_Field.value
str_Filename = reports!&str_RptName&.caption


Can this be done? Additionally, is there anyway to make sure doing this
triggers ON OPEN since I ahve code in there that tailors the caption to what
I want?

I can'tr eally hard code the name because the code I'm writing should do
this for ANY of my reports, and they are all drastically different.

Thanks.
 
J

Jack Leach

I think this should work. For the record, you won't be able to access any
properties of the report unless it's opened, so your open event should always
run. Make it a point to open the report in preview mode and hidden and your
open event will run before you do any printing or exporting.

(this is complete aircode but should be pretty close)

Function MakeNewPDF(sReport As String)

Dim sCaption As String
Dim sFileName As String

'open in preview/hidden to get the openevent to run...
'Stephen uses OutputTo for his converter, which will not fire the event

DoCmd.OpenReport sReport, acViewPreview, , , acHidden

'your open even has now run, the report is there, so pull the caption
sCaption = Reports(sReport).Caption

'make your filename
'be wary of bad filename characters in your caption, btw
sFileName = "C:\YourPath\" & sCaption & ".pdf"

'convert the report to PDF (it is still open, this will retain any
'info you use in the open events... the only way to do this
'when using OutputTo
ConvertReportToPDF sReport, , sFileName

'now close the report
DoCmd.Close acReport, sReport, acSaveNo

End Function



hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

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