473,394 Members | 1,751 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,394 software developers and data experts.

use DoCmd.OutputTo to export a PDF of the current record on a report?

20
Hello,

I want to create a button on a form that exports the current record on the form to a PDF of a report. I've taken the code i found here:

http://bytes.com/topic/access/answers/909411-can-i-use-docmd-outputto-export-current-record-only

and modified it to be this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command481_Click()
  2.  
  3. Dim strOriginalRecordSource As String
  4. Dim strNewRecordSource As String
  5.  
  6. strOriginalRecordSource = Me.RecordSource
  7. strNewRecordSource = "SELECT * FROM [qry_Projects Credits] WHERE [Project Number] = " & Me![Project Number]
  8.  
  9. Me.RecordSource = strNewRecordSource
  10.  
  11. DoCmd.OutputTo acOutputReport, "rpt_Projects Credits", acFormatPDF, , True, "", 0
  12.  
  13. Me.RecordSource = strOriginalRecordSource
  14.  
  15. End Sub
The form is based on the query "qry_Projects Credits". The primary key is "Project Number". The report i want to export to is called rpt_Projects Credits. When I try to run this i get the error:

Run-Time Error '3075': Syntax error (missing operator) in a query expression '[Project Number]='

When I click "Debug" it points to this line:

Expand|Select|Wrap|Line Numbers
  1. Me.RecordSource = strNewRecordSource
I have some experience with programming in C++ from a couple of courses i took a while ago (one first year university programming course and a robotics course later). I think i understand the logic that the code is trying to carry out but im still very new to VBA and am unfamiliar with the syntax.

Thanks,

Xenver
Jul 22 '14 #1
7 4697
twinnyfo
3,653 Expert Mod 2GB
Is you rfirst block of code in your form or report? As it looks to me right now, it is taking the record source for the current Form and changing it, but you are doing nothing to change the record source of the Report.

You could modify the code and place it in the OnOpen event of the Report, but you would run into problems if this report were called independently of hte Form (and if the form had a null value for the Project Number).

Lots of questions about this post, but we're willing to look into it if we get a little more information.
Jul 22 '14 #2
Xenver
20
There are other blocks of code, but i don't think they'll interfere with this one, for the most part they just open/ close forms with the DoCmd.Open[object type] or DoCmd.Close commands. The only one more complicated than that runs an append query that updates the query that this form uses and sets warnings off/turns them on, it looks like this:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings (WarningsOff)
  2. DoCmd.OpenQuery "Project to project credits Project Number"
  3. DoCmd.SetWarnings (WarningsOn)
  4. DoCmd.OpenForm "frm_Projects Credits"
I thought by modifying the record source of "qry_projects Credits" I would in-turn modify the record source for the report because the report is based on that query.I'm more than willing to tell you anything you need to know, but I'm a little hesitant to post the whole database.
Jul 22 '14 #3
twinnyfo
3,653 Expert Mod 2GB
1. I don't need you to post the whole db.

2. Is your first code block in Post #1 on your FOrm or on your report? Even if you change the record source for the Form, you do nothing to the record source of the report. You are not changing the query, just the record source. You must do the same for the report....
Jul 22 '14 #4
Xenver
20
The Button is on the form. I think i see what you're saying, I need to change the record source of the report, not the form. How do i go about doing that while keeping the button on the form?

I thought by using these lines:

Expand|Select|Wrap|Line Numbers
  1. strNewRecordSource = "SELECT * FROM [qry_Projects Credits] WHERE [Project Number] = " & Me![Project Number]
  2. Me.RecordSource = strNewRecordSource
I would be changing the record source of the query, but i guess i just changed the record source of the form to the query containing only the current record, is that right?
Jul 22 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Let's start by playing with this code that you already have. No guarantees that it will work right away, but place this in your report's Module:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.     Dim strNewRecordSource As String 
  3.  
  4.     strNewRecordSource = "SELECT * FROM [qry_Projects Credits] " & _
  5.         "WHERE [Project Number] = " & _
  6.         Forms![Your Form Name].[Project Number] & ";"
  7.  
  8.     Me.RecordSource = strNewRecordSource
  9.     Me.Requery
  10. End Sub
I must admit that I've never tried to change the record source of a report that is already open, so I don't know what the results will be (and I don't know if it will output to PDF properly, either).

There are other ways of doing this, such as using the form controls in your actual query, but, again, if the Report ever opens independently of the Form, you will have problems.

This might point you in the right direction for now....
Jul 22 '14 #6
Xenver
20
I'm sorry, I must have mislead you, the report will not be open when the button is pressed. With the code you gave me in the report's module the button creates a shortcut to a pdf that doesn't exist in my recent items. The shortcut says it's target is a PDF in my documents folder but windows cannot find the document and it doesn't seem to exist.

also when i press the export button now it prompts me to input a value for whatever the project number is, for example, if the project number is 123456 the prompt would say "enter a value for 123456" I've just been inputting the project number.

Also this isn't new with the addition of the code you gave me, but i think is caused by some changes i made to the original code i found: When I open my form it prompts me to "enter a value for Me.Project_Number, again I've just been entering the project number I just created (all these forms are on a new project form progression). I'm not sure what caused this but before the project number displayed would just default to the latest one created, which is what i want.
Jul 22 '14 #7
Xenver
20
Hello, i realize I'm probably not making much sense, so i made a stripped down version of the db for you to look at, there are still some buttons that don't work and stuff, but it should get the point across. Hope this helps. yes i know the tbl_Projects_Credits is a nightmare in terms of normalization, but it's all i could figure out within the time i can devote to this.
Attached Files
File Type: zip Project Database for forum.zip (760.3 KB, 121 views)
Jul 22 '14 #8

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

Similar topics

3
by: Jorge Cecílio | last post by:
Hi! I would like to export some MS-Access reports output to pdf. However, the only possibility offered by Access (afaik) for me to export formatted output is snp (snapshot) (I use MS-Office...
1
by: Ryan | last post by:
Hello. I was hoping that someone may be able to assist with an issue that I am experiencing. I have created an Access DB which imports an Excel File with a particular layout and field naming. ...
3
by: ljungers | last post by:
I need to make some changes to a Query/select/print report using word application. What I need to do is change the way Word is called yet keep the process the same. Word is used so changes can be...
1
by: inika301 | last post by:
Mr Lebans. Could you help me ? We are trying to run your mdb to convert access reports to pdf but we can not, because an error happens. We are just using the A2000SnapShotToPDFver751 that is...
4
ollyb303
by: ollyb303 | last post by:
Hi, I have a problem I need some help with. In my Access 2000 database (used for logging complaints to my company), I'm using the following code to send an email to our finance dept when a...
5
by: Lewe22 | last post by:
I am exporting snaphot files on 1st of each month. I want each file i export to automatically insert the current date. I have set the current date to a variable named DateTime and tried inserting...
2
by: jmartmem | last post by:
Greetings, I have several Access 2007 reports that I regularly export to individual PDF flat files on a web server. I've successfuly created a module sub to export the reports using the...
2
by: Tim F | last post by:
Hello all, I would like to create a command button on a form that will allow the user to export the current record to .xls. The following exports the entire table. Is there a way to export the...
0
by: Mauno Ahonen | last post by:
Hi. I'm having trouble exporting the current record displayed on a form to a PDF file. Please keep in mind that I'm a complete newb when it comes to Access and VBA. This is what I've come up with...
1
Seth Schrock
by: Seth Schrock | last post by:
I have an image in the page header of my report. I'm trying to export my report to a PDF file, which it does, but it doesn't include the image. Here is my codeDoCmd.OutputTo acOutputReport,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.