export report with variable data

D

dgeffs

I need to export a report in Access 2007 to a pdf file. I know this is
supported but how does one specify parameters for the report to export? There
is no where clause in the output to method and I want to export this without
actually opening the report.
 
J

Jeff Boyce

Until the report "opens", I don't believe it "knows" what data it has. And
you're calling it "export ... to pdf", but aren't you actually "printing" it
into a .pdf file?

Could you use the query that underlies the report instead, and export
(?!print?!) that?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
D

Dale Fye

I usually do this one of two ways.

1. Create an unbound textbox on a form and bind the query that supports the
report to that textbox via a WHERE clause in the query.

WHERE Forms!yourFormName.txt_Criteria IS NULL
OR [SomeField] = Forms!yourFormName.txt_Criteria

2. Create a function that I can pass values to, and use that function in
your where clause. I do this when I have the same report that I want to use
with multiple forms, and prefer this method over creating a global variable
for a couple of reasons. The first time you use this, you pass it a value
(you could put this line immediately before you call your Output method.

Call fnSomeValue(23)

after that, you can just use it in your query:

SELECT * FROM yourTable
WHERE [SomeField] = fnSomeValue()

Public Function fnSomeValue(Optional PassedVal As Variant = Null) As Variant

Static myVal As Variant

If Not IsNull(PassedVal) Then
myVal = PassedVal
ElseIf IsMissing(myVal) Or IsEmpty(myVal) Then
myVal = Null
End If

fnSomeValue = myVal
End Function

HTH
Dale
 
D

dgeffs

Printing to PDF is exactly what I am attempting to do. The PDF file needs to
look exactly like the report but I don't want to open the report. Actually I
am trying to do something I used to do in Access 2003 that used a third party
piece of code to create the PDF file using Acrobat or other PDF creation
software. It allowed me to pass the report criteria (where clause) directly
to the function and it created the report in PDF format using that criteria.
Now since Access 2007 natively supports PDF creation I am trying to convert
the function.

i don't think using just the query and outputting that data would retain the
report formatting etc. unless I am missing something (always a possibility).
 
D

dgeffs

Both of these are interesting and I suspect one will work for my needs. I
can't believe I didn't think of the first one. It seems so obvious - must
have been a brain freeze. Thanks.

Dale Fye said:
I usually do this one of two ways.

1. Create an unbound textbox on a form and bind the query that supports the
report to that textbox via a WHERE clause in the query.

WHERE Forms!yourFormName.txt_Criteria IS NULL
OR [SomeField] = Forms!yourFormName.txt_Criteria

2. Create a function that I can pass values to, and use that function in
your where clause. I do this when I have the same report that I want to use
with multiple forms, and prefer this method over creating a global variable
for a couple of reasons. The first time you use this, you pass it a value
(you could put this line immediately before you call your Output method.

Call fnSomeValue(23)

after that, you can just use it in your query:

SELECT * FROM yourTable
WHERE [SomeField] = fnSomeValue()

Public Function fnSomeValue(Optional PassedVal As Variant = Null) As Variant

Static myVal As Variant

If Not IsNull(PassedVal) Then
myVal = PassedVal
ElseIf IsMissing(myVal) Or IsEmpty(myVal) Then
myVal = Null
End If

fnSomeValue = myVal
End Function

HTH
Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



dgeffs said:
I need to export a report in Access 2007 to a pdf file. I know this is
supported but how does one specify parameters for the report to export? There
is no where clause in the output to method and I want to export this without
actually opening the report.
 

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