473,473 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Carrying data from form to report

3 New Member
I'm developing A/R statements from a table that contains 1 record per customer that I'm reading sequentially through a form. After reading each record I'm then calling the report using
DoCmd.OpenReport "SCUS", acViewPreview, , , , vPassedVariable, but I cannot see the value of vPassedVariable in the report program. Within the report program I need to then join the vPassedVariable to a key field in another detail table via a SQL statement in order to get all of the data on the report for a single customer. I'm then exiting the report and saving the print preview as a PDF. The form will then read the next record and call the report again, save as pdf for about 1,500 customers.

What am I missing in not being able to bring the vPassedVariable from the form to the report?
Oct 22 '15 #1
4 1231
jforbes
1,107 Recognized Expert Top Contributor
Here is some code I use to create Quote PDFs, which is very similar to what you are doing. I hid some of the unrelated code. I think what you will be most interested in is the Where Condition of the DoCmd.OpenReport:
Expand|Select|Wrap|Line Numbers
  1. Public Function generateQuotePDF(ByRef sQuoteNumber As String) As String
  2.  
  3.     Dim sFileName As String  
  4.  
  5.     sFileName = sQuoteNumber & "_" & getStringDateTime()& ".PDF"   
  6.  
  7.     Application.Echo False
  8.     DoCmd.OpenReport "rptQuote", acViewPreview, , "QuoteNumber='" & sQuoteNumber & "'"
  9.     DoCmd.OutputTo acOutputReport, "rptQuote", acFormatPDF, gQuoteDirectory & sFileName, False
  10.     DoCmd.Close acReport, sReportName
  11.     Application.Echo True
  12. ...
This code will create the PDF with minimal screen updating and just a print notification showing on the screen.
If you set the AutoStart parameter of DoCmd.OutputTo to "True" it will display the PDF to the user after it has been created:
Expand|Select|Wrap|Line Numbers
  1.     DoCmd.OutputTo acOutputReport, "rptQuote", acFormatPDF, gQuoteDirectory & sFileName, True
Oct 22 '15 #2
Bill7927
3 New Member
@jforbes
Thank you for your reply. I believe I have the form coded as you instructed, but I'm not sure how to reference the field in the report program in order to use in in the SQL statement.

That is from your example, how do you reference or use the sQuoteNumber in the report program?
Oct 22 '15 #3
jforbes
1,107 Recognized Expert Top Contributor
I should back up a bit and explain that there are two approaches to limiting a Reports output.
  1. Defining the RecordSource when Opening the Report - This is done by passing a Key Value in the OpenArg Parameter (Or Global variable or TempVar). The last parameter in DoCmd.OpenReport, OpenArgs, gets stuffed into the OpenArgs Propery on the Report, which can then be used to define a Record Source. This is an example that is similar, but for filtering a Form: https://msdn.microsoft.com/en-us/lib.../ff836583.aspx

    I believe this is the way you originally started developing the Report. You would then write some code to use OpenArgs and build a SQL Statement for the RecordSource. This approach will work, but I wouldn't recommend it as the Next approach is easier to Develop and easier to use.
  2. Passing a Where Clause with DoCmd.OpenReport. This link has three different examples: https://msdn.microsoft.com/EN-US/lib.../ff820845.aspx
    This is also the example I provided. The idea behind this it to Write your Report with no Filtering at all. Get it to display the way you want. I often, put in a Group on the Key Value. In the example above, the Report is Grouped by QuoteNumber, which aligns the Report correctly on the Page. Then when opening the Report, limit the report to only the single Key value that is of interest.

    This is what is being done in the example I provide by the variable sQuoteNumber. The QuoteNumber is passed in sQuoteNumber and then the Where Clause of "QuoteNumber='" & sQuoteNumber & "'" is passed to the Report, which then limits the Report to the One Desired Quote.
Oct 22 '15 #4
Bill7927
3 New Member
Thanks again, that fixed it! I took your advice and simplified the report by removing the SQL code and grouped by the customer number from the form. Works great!

Your help is greatly appreciated!
Oct 22 '15 #5

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

Similar topics

3
by: David C. Allen | last post by:
I am following thru the examples in the book I am studying for my MCSD. This is the web applications book. One example is to use the data form wizard to create a simple data form on the...
1
by: Scott Sabo | last post by:
I have a form & report based on a query which shows details about employees performance reviews (hire date, review date, review submital date, etc). We do 90 day probation reviews as well and I...
0
by: ghadley_00 | last post by:
MS Access Create form / report with multiple pages using different background images Hi, Would like to have users fill out a multipage form, and then click a print button, which pulls up the...
6
by: Bob | last post by:
I've located instruction as to how to add the Data Form Wizard into a VB.NET 2005 project at this location. ...
3
by: nkoriginal | last post by:
Hello: I tried an script for keep my data form after reload page, but I've some errors. In this momento I runnung my own browser because we've an intranet. And for security reason, our page...
1
by: EgoSum | last post by:
Does anybody can explain in steps how can I load xml data in report and open it in reportViewer? There's a short xml example ProductSales.xml: <?xml version="1.0" standalone="yes"?>...
3
by: Mac Campbell | last post by:
For some unknown reason my mdb seemed to drop a module I had named "Utilities". I tried to copy the module back in from a backup copy and got the error message "<<MyProject>> is currently unable to...
3
by: STEPHENSS | last post by:
Hi, I have a crystal report that has many subreports over many pages and Iam getting the following error Unable to save data with report, the save data is incomplete generate the saved data Yes...
3
by: MyWaterloo | last post by:
I am trying to open my purchase orders form and go to the last record. In the on open command I do: DoCmd.GoToRecord , , acLast Seems straight forward enough...but I keep getting this message...
3
beacon
by: beacon | last post by:
Hi everybody, I'm using Access 2010, but the format for the database is .mdb because I'm not ready to fully convert it to Access 2010 and the .accdb format. I've been reading up on how to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.