 |

10-06-2010, 11:11 AM
|
|
Newcomer
|
|
Join Date: Oct 2010
Posts: 4
|
|
multiple PDFs from VBA in Access?
|
I have a working query linking three tables, and I have a working report. I'm having trouble combining the two.
I want to use doCmd.OutputTo so I can specify the name of the PDF, which is already stored in a table. But this does not allow a WHERE clause, and I want each report to print only an individual client.
I can add the client number to the query criteria, and it works great. For that single client.
The report specifies the query in the record source, which seemed like the easiest way to deal with three big interconnected tables. (I suspect this is where the problem is.)
So I either need a way to programatically change the query criteria for each client, or some other way of getting a report with only one client instead of all of them. My code looks like this:
Code:
Public Function print_individual_clients()
Dim MyDB As DAO.Database
Dim rstParseNames As DAO.Recordset
Dim stDocName As String
Dim stOutput As String
Dim stJustOne As String
Dim stSQL_Text As String
Set MyDB = CurrentDb
Set rstParseNames = MyDB.OpenRecordset("Clients", dbOpenDynaset)
With rstParseNames
If Not .BOF And Not .EOF Then
Do While Not .EOF
stJustOne = ![Clientid]
DoCmd.OpenQuery "Report Query"
'Need code here that filters out all but stJustOne
stOutput = "C:\Client_PDFs\" & ![NEW_FILENAME] & ".PDF"
MsgBox "Print PDF to " & stOutput
stDocName = "Client Report"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, stOutput, True
' If I could just put WHERE client=stJustOne that would do it
.MoveNext
Loop
Else
' we're done
End If
End With
rstParseNames.Close
Set rstParseNames = Nothing
MsgBox "Finished printing each client at " & Now
End Function
|
|

10-06-2010, 12:20 PM
|
|
Newcomer
|
|
Join Date: Oct 2010
Posts: 4
|
|
It might be helpful to see the SELECT statement my query generates:
Code:
SELECT Sites.SiteID, Clients.Location, Sites.Customer, Sites.Site, Clients.ACDC,
Sites.Address, Sites.Phone, Sites.Fax, Sites.Area, Sites.Region, Sites.Contact,
Clients.ClientID, Clients.ID, Clients.Type, Clients.Capacity, Clients.CrManuf,
Clients.CrSerNo, Clients.HManuf, Clients.HSerNo, Clients.Lift, Clients.Span,
Clients.Voltage, Clients.DlvDate, Clients.OperHY, Clients.CrGroup, Clients.Notes,
Checklists.CompID
AS Checklists_CompID, Checklists.Desc, CompLib.CompID
AS CompLib_CompID, CompLib.Item, CompLib.[I#], CompLib.Name, CompLib.SMEH,
Checklists.SMEH
FROM (Sites INNER JOIN Clients ON Sites.SiteID = Clients.SiteID)
INNER JOIN (CompLib INNER JOIN Checklists ON CompLib.CompID = Checklists.CompID)
ON Clients.ClientID = Checklists.ClientID
WHERE (((Clients.ClientID) = [JustOneParam]))
ORDER BY Clients.Location;
|
|

10-11-2010, 11:39 PM
|
 |
Regular
|
|
Join Date: Jan 2005
Location: Gold Coast, Australia
Posts: 68
|
|
create pdf files using VB and MS Access.
TomKing,
You might want to check out this post....
http://www.xtremevbtalk.com/showthread.php?t=301733
In short it adds a PDF creation class to your project and you can build a PDF on the fly and put in a save location and file names.
I have had a lot of problems and errors trying to create pdf files using VB and MS Access.
Hope it helps.
Cheers.
Disco Stu.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|