By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

automating report print....

P: 31
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
Share this Question
Share on Google+
5 Replies


ADezii
Expert 5K+
P: 8,607
@totomalas
  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

P: 31
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

ADezii
Expert 5K+
P: 8,607
@totomalas
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
  3.  
  4. Set MyDB = CurrentDb
  5. Set rstEmployee = MyDB.OpenRecordset("Employees", dbOpenForwardOnly)
  6.  
  7. With rstEmployee
  8.   Do While Not .EOF
  9.     Debug.Print ![EmployeeID] & " " & ![FirstName] & " " & ![LastName]
  10.       .MoveNext
  11.   Loop
  12. End With
  13.  
  14. rstEmployee.Close
  15. Set rstEmployee = Nothing
OUTPUT:
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

P: 31
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]
.MoveNext
DoCmd.OpenReport "Test", acViewNormal, "", "", acNormal

Loop
End With
rstEmployee.Close
Set rstEmployee = Nothing
Aug 3 '09 #5

ADezii
Expert 5K+
P: 8,607
@totomalas
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.