Hi,
I've now been working on and off this issue for the last couple of days and i'm not getting any further on it. I wondered if anyone could possibly give me a hand?
I am most definitely not a programmer by any means although I have dabbled in the very basics of a few languages on a personal level in the past. This week I've been tasked with learning both Access and VBA to get this working so it's been a difficult couple of days! :banghead:
Basically we have a report that prints out our remote support for the past 30 days or so based on whether "Invoiced" is ticked on or off. If it's not ticked, it prints that page.
We're trying to get this report to export all pages to PDF's based on "Customer" name. Using various butchered code mangled together into Frankensteins monster, I think i'm kind of close-ish to achieving this goal.
I now have it exporting 30 odd pages of reports to 30 individually named PDF files. The only (rather large issue) is that each PDF contains all 30 pages of customers support instead of the one or two pages it should contain for that single customer!
This last step is proving a bit of a cliff face and nothing I am finding is helping me over it. Wondering if someone could possibly give me some pointers as to where I am going wrong?
I *think* I need to somehow have the below line look for the customer somehow (as per my botched up example) and only open that single page of the report. If I can do that then I think I am home and dry? I would then need to add something to say "don't print the invoice if [Invoice] = yes" but that sounds pretty simple to achieve compared to all the other hurdles I've crawled over so far. The most amusing was when I inadvertently removed "acViewPreview" which caused it to print 30 x 30 pages to my default printer. Oh how we laughed...
The below code was from an example which suggested I should be able to use a field reference from the report to print just that page but if I try manually typing in a customer name there to test, Access pops up a text type window and waits for me to enter something then proceeds to create that PDF but with nothing in it.
The below code has a few parts intentionally commented out. The loop seems unnecessary until I can get the first page to come out without all 30 pages attached to it. And I didn't really understand what the forms bits do and couldn't see that they were helping any so they are also commented out. I've left them there in case they do help in some way I don't understand.
Note that I do have a similar request up on Experts Exchange but other than a single response, it has been ignored. This board looks a lot more active so thought i'd give this a go. Hope this isn't a problem? I'm very happy to remove the experts Exchange post if it helps.
I've now been working on and off this issue for the last couple of days and i'm not getting any further on it. I wondered if anyone could possibly give me a hand?
I am most definitely not a programmer by any means although I have dabbled in the very basics of a few languages on a personal level in the past. This week I've been tasked with learning both Access and VBA to get this working so it's been a difficult couple of days! :banghead:
Basically we have a report that prints out our remote support for the past 30 days or so based on whether "Invoiced" is ticked on or off. If it's not ticked, it prints that page.
We're trying to get this report to export all pages to PDF's based on "Customer" name. Using various butchered code mangled together into Frankensteins monster, I think i'm kind of close-ish to achieving this goal.
I now have it exporting 30 odd pages of reports to 30 individually named PDF files. The only (rather large issue) is that each PDF contains all 30 pages of customers support instead of the one or two pages it should contain for that single customer!
This last step is proving a bit of a cliff face and nothing I am finding is helping me over it. Wondering if someone could possibly give me some pointers as to where I am going wrong?
I *think* I need to somehow have the below line look for the customer somehow (as per my botched up example) and only open that single page of the report. If I can do that then I think I am home and dry? I would then need to add something to say "don't print the invoice if [Invoice] = yes" but that sounds pretty simple to achieve compared to all the other hurdles I've crawled over so far. The most amusing was when I inadvertently removed "acViewPreview" which caused it to print 30 x 30 pages to my default printer. Oh how we laughed...

The below code was from an example which suggested I should be able to use a field reference from the report to print just that page but if I try manually typing in a customer name there to test, Access pops up a text type window and waits for me to enter something then proceeds to create that PDF but with nothing in it.
Code:
DoCmd.OpenReport "Remote Support Report", acViewPreview, , "Customer = CUSTOMER NAME"
The below code has a few parts intentionally commented out. The loop seems unnecessary until I can get the first page to come out without all 30 pages attached to it. And I didn't really understand what the forms bits do and couldn't see that they were helping any so they are also commented out. I've left them there in case they do help in some way I don't understand.
Note that I do have a similar request up on Experts Exchange but other than a single response, it has been ignored. This board looks a lot more active so thought i'd give this a go. Hope this isn't a problem? I'm very happy to remove the experts Exchange post if it helps.
Code:
Sub Main()
Dim rst As ADODB.Recordset
Dim MyFileName As String
Dim mypath As String
mypath = "C:\Temp\Remote\"
Set rst = New ADODB.Recordset
rst.Open "Select distinct [Customer] From [Remote Support Query]", CurrentProject.Connection
'Do While Not rst.EOF
' Forms![Remote support].Customer.Value = 0
MyFileName = rst("Customer") & ".pdf"
' Forms![Remote support].Customer.Value = rst!Customer
DoCmd.OpenQuery "Remote Support Query"
DoCmd.Close acQuery, "Remote Support Query", acSaveYes
DoCmd.OpenReport "Remote Support Report", acViewPreview
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
DoCmd.Close acReport, "Remote Support Report", acSaveYes
DoEvents
rst.MoveNext
' Loop
rst.Close
Set rst = Nothing
End Sub