473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Access VBA generate individual PDF for each row

10 Byte
Hello,

I don't really know anything about VBA. I need to generate a pdf for each groupid named with the groupid. I found some code and repurposed it. Someone was doing the same thing as I but it is not working. The groupids do not match the groupid and that groupid's associated data in the pdf. So for example groupid 555.pdf file does not contain groupid 555 associated data. Each generated pdf contains the same groupid data while the name of the pdf is created as I desire it to. There are not any error messages.

Form1 contains three fields. The groupid, and two associated data fields. Query3 pulls the data from form1 for whatever row the form is open to. Query3 data goes to a report that displays one row at a time. I run the code in a module.


This is the code for the query3.
Expand|Select|Wrap|Line Numbers
  1. SELECT [groupidquery].groupid, [groupidquery].Expr1, [groupidquery].Expr2
  2. FROM [groupidquery]
  3. WHERE ((([groupidquery].groupid)=[Forms]![Form1]![groupid]));
This is the module code

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3.  
  4. Private Sub FFS()
  5.  
  6.  Dim db As DAO.Database
  7.     Dim rs As DAO.Recordset
  8.     Dim MyFileName As String
  9.     Dim mypath As String
  10.     Dim temp As String
  11.  
  12.     mypath = "C:\Users\myfolder\folder\"
  13.  
  14.     Set db = CurrentDb()
  15.  
  16.     Set rs = db.OpenRecordset("SELECT DISTINCT [groupid] FROM [groupidquerymain]", dbOpenSnapshot)
  17.  
  18.     Do While Not rs.EOF
  19.  
  20.         Forms![Form1].groupid.Value = 0
  21.  
  22.         temp = rs("groupid")
  23.  
  24.         MyFileName = rs("groupid") & ".pdf"
  25.  
  26.         Forms![Form1].groupid.Value = rs!groupid
  27.  
  28.       DoCmd.OpenForm "Form1"
  29.       DoCmd.GoToRecord , acDataForm, acGoTo, "temp"
  30.       DoCmd.OpenQuery "query3"
  31.       DoCmd.Close acQuery, "query3", acSaveYes
  32.       DoCmd.OpenReport "Report1", acViewPreview
  33.       DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
  34.       DoCmd.Close acReport, "groupidquery", acSaveYes
  35.  
Jun 25 '20 #1

✓ answered by Gilley178

One of the queries was not pulling data from the right table. At least that is my theory but it works now. I would now consider it to be working.

1 2906
Gilley178
10 Byte
One of the queries was not pulling data from the right table. At least that is my theory but it works now. I would now consider it to be working.
Jun 29 '20 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Brian | last post by:
Hello, I have a text file I'm attempting to parse. There are about 50 fixed width fields in each line / row. For example (shortened for brevity): W1234Somebody East 101110001111010101...
1
by: Erinys | last post by:
Hi, I need to access the individual bytes in a string in my javascript function. If the characters in the string were all ascii characters then there would not be a problem, however in my case...
10
by: shaji | last post by:
Hi, Could anybody tell me how to access the individual bytes that consists of a Windows LONGLONG value?
1
by: nmeyer | last post by:
Hi, I'm trying to scope a MS Access project and was looking for some advise. Will VB programming/ experience be required to build out something like the Northwinds sample database? We'd like a...
8
by: voltrate | last post by:
Hi, I am a newbie to Access. Planning to create a receipt issuing module where a new receipt with a new running number is created after the previous receipt is saved. Is this possible? Thanks.
60
by: aboxylica | last post by:
my file is of the form 01 "\t" 10.19 "\t" 0.00 "\t" 10.65 02 "\t" 11.19 "\t" 10.12 "\t" 99.99 and...
1
by: dbdevusr23 | last post by:
I am very new to writing code, and this is what I need to do: I have two Access reports, Report_1 and Report_2, that I need to export into an Excel spreadsheet, creating a tab for each report. I...
1
by: DKF9 | last post by:
Hi. I need some help in transferring data from a Lotus Approach database into Access. I have a field in Approach that is like a memo field in Access. There are many lines of data for each row....
4
by: Bikash Kumar Mishra | last post by:
how to access the bits of a value stored in memory as such?
0
by: Steve Chong | last post by:
First post! So I've been trying to figure out how the heck I'm gonna do this. It's been driving me up the wall this past week so I figure this website would maybe be of some help. I'm new to using...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.