470,573 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

automating report print....

I have developed a report in Access 2007 that runs on three queries, each promting an input from the user...this report is used for a meeting and it should be printed nine times...what I do now is open the report nine times, with each print i enter the same inputs for the first two queries and a different input for the third one...so this is becoming a hassle for me.. :(

Query1 takes the meeting date
Query2 takes the budget date
Query3 takes the member's ID ( the list of ID's is stored in a table in the database)

so in each print, the only difference is the member's ID...but now I enter the meeting date and the budget date again and again for each print.. :(

is there a way to have a loop that takes the input for the first two queries once and stores it in a variable, and reads the value for the third query from the table (with each cycle it reads the next record and gives it to the query, instead of promting the user to enter it)?...

Or atleast save the inputs for the 1st two queries and prompt only for the member's ID..

I am really desperate to have this Loop...thanks

p.s I dont have any experience in VB programming
Aug 2 '09 #1
5 2507
8,800 Expert 8TB
  1. Create a Form, and for the sake of simplicity, let's call it frmCriteria.
  2. Create 2 Text Boxes on this Form and Name them txtMeetingDate and txtBudgetDate.
  3. In the appropriate Fields in your Queries, instead of the Parameter Prompts, set the Criteria to the Form Fields, as in:
    Expand|Select|Wrap|Line Numbers
    1. [Forms]![Form1]![txtMeetingDate]     'for the [Meeting Date] Field
    2. [Forms]![Form1]![txtBudgetDate]      'for the [Budget Date] Field
  4. The Criteria will be read via the Form Fields and you will not be prompted for a Meeting or Budget Date.
  5. You can still set the Criteria for ID in the usual manner in conjunction with the above, as in:
    Expand|Select|Wrap|Line Numbers
    1. [ENTER Employee ID]
  6. If you have a mechanism for retrieving the Employee ID, you can automate the prompting of that value also.
  7. Before opening the Reports that are based on these Queries, you should make sure that Valid Dates are entered in txtMeetingDate and txtBudgetDate, as in:
    Expand|Select|Wrap|Line Numbers
    1. If IsDate(Me![txtMeetingDate]) And IsDate(Me![txtBudgetDate]) Then
    2.   DoCmd.OpenReport "<Report Name>", acViewNormal Or acViewPreview, , , acWindowNormal
    3. Else
    4.   MsgBox "You must enter Valid Dates for both Meeting and Budget", vbExclamation, _
    5.          "Missing/Invalid Date Entries"
    6. End If
  8. Any questions, feel free to ask.
Aug 2 '09 #2
Thanks alooooooot..

this is a great solution...it works very well....

No I dont have any mechanism for retrieving the Employee ID...I was thinking of some sort of a loop in VB that takes all the records in the Employee Table one by one..all i have is nine employee, and their names must be on those report,,each by himself only...but i dont know how to write such loop.. :s
Aug 2 '09 #3
8,800 Expert 8TB
The following code will loop through the Employees Table of the sample Northwind Database, and Print to the Immediate Window the Employee's ID, First Name, and Last Name. Oddly enough, this Table also contains 9 Employees.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rstEmployee As DAO.Recordset
  4. Set MyDB = CurrentDb
  5. Set rstEmployee = MyDB.OpenRecordset("Employees", dbOpenForwardOnly)
  7. With rstEmployee
  8.   Do While Not .EOF
  9.     Debug.Print ![EmployeeID] & " " & ![FirstName] & " " & ![LastName]
  10.       .MoveNext
  11.   Loop
  12. End With
  14. rstEmployee.Close
  15. Set rstEmployee = Nothing
Expand|Select|Wrap|Line Numbers
  1. 1 Nancy Davolio
  2. 2 Andrew Fuller
  3. 3 Janet Leverling
  4. 4 Margaret Peacock
  5. 5 Steven Buchanan
  6. 6 Michael Suyama
  7. 7 Robert King
  8. 8 Laura Callahan
  9. 9 Anne Dodsworth
Aug 2 '09 #4
Yes that works..this is the code that worked for me... THANKS :)

Dim MyDB As DAO.Database
Dim rstEmployee As DAO.Recordset
Dim Name As String
Dim Title As String
Set MyDB = CurrentDb
Set rstEmployee = MyDB.OpenRecordset("Members", dbOpenForwardOnly)

With rstEmployee
Do While Not .EOF
DoCmd.OpenReport "Test", acViewReport, "", "", acNormal
Name = ![Mamber's Name]
Title = ![Title]
[Reports]![Test]![txtName] = Name
[Reports]![Test]![txtTitle] = Title
Debug.Print ![ID] & " " & ![Mamber's Name] & " " & ![Title]
DoCmd.OpenReport "Test", acViewNormal, "", "", acNormal

End With
Set rstEmployee = Nothing
Aug 3 '09 #5
8,800 Expert 8TB
Glad you got it all to work for you.
Aug 3 '09 #6

Post your reply

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

Similar topics

4 posts views Thread by Supa Hoopsa | last post: by
2 posts views Thread by Dave | last post: by
1 post views Thread by karthik2423 | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.