Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > multiple PDFs from VBA in Access?


Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2010, 11:11 AM
tomking tomking is offline
Newcomer
 
Join Date: Oct 2010
Posts: 4
Default 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
Reply With Quote
  #2  
Old 10-06-2010, 12:20 PM
tomking tomking is offline
Newcomer
 
Join Date: Oct 2010
Posts: 4
Default

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;
Reply With Quote
  #3  
Old 10-11-2010, 11:39 PM
Disco Stu's Avatar
Disco Stu Disco Stu is offline
Regular
 
Join Date: Jan 2005
Location: Gold Coast, Australia
Posts: 68
Default 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.
Reply With Quote
Reply

Tags
vba access pdf


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->