473,671 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing several records from a form - looping through

2 New Member
Hi

I've inherited an Access database where there is a form setup which prints out a Job Sheet. This works fine with one record. However I need to set it to loop through several records and print them all out programmaticall y.

This is my code which appears to work fine, but doesn't loop through the records, just prints off the first record however many times there are records to print. This is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2. On Error GoTo Err_cmdOK_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.     Dim db As DAO.Database
  7.     Dim rst As DAO.Recordset
  8.     Dim strdate As String
  9.     Dim strRanger As String
  10.     Dim qryName As String
  11.     Dim tblName As String
  12.     Dim strSQL As String
  13.     Dim i As Integer
  14.  
  15.     stDocName = "frmJobSheetTrimble"
  16.     tblName = "tblTempJobSheet"
  17.     qryName = "qryJobSheetByDate"
  18.  
  19.     strSQL = "delete from tblTempJobSheet"
  20.  
  21.     DoCmd.SetWarnings False
  22.     DoCmd.RunSQL strSQL
  23.  
  24.     DoCmd.OpenQuery qryName, acViewNormal ' This creates the temporary table to print the record from.
  25.  
  26.     Set db = CurrentDb()
  27.     Set rst = db.OpenRecordset("tbltempJobSheet")
  28.  
  29.     i = 0
  30.     MsgBox "You are about to print" & " " & Count & " " & "records.", vbOKCancel
  31.  
  32.     DoCmd.OpenForm stDocName, , , , , acWindowNormal
  33.  
  34.             rst.MoveFirst
  35.                 Do While Not rst.EOF
  36.                     i = i + 1
  37.                     If rst![SpecificRiskAss] = True Then
  38.                        DoCmd.PrintOut acPages, 1, 2, , , Yes
  39.  
  40.                     End If
  41.  
  42.                     If rst![SpecificRiskAss] = False Then
  43.                        DoCmd.PrintOut acPages, 1, 1, , , Yes
  44.                     End If
  45.  
  46.             rst.MoveNext
  47.         Loop
  48.  
  49.     rst.close
  50.  
  51.     Set rst = Nothing
  52.     Set db = Nothing
  53.  
  54.     DoCmd.SetWarnings True
  55.     DoCmd.close acForm, stDocName
  56.  
  57.     stDocName1 = "frmJobSheetPrinted"
  58.     DoCmd.OpenForm stDocName1, , , stLinkCriteria
  59.  
  60. Exit_cmdOK_Click:
  61.     Exit Sub
  62.  
  63. Err_cmdOK_Click:
  64.     MsgBox Err.Description
  65.     Resume Exit_cmdOK_Click
  66.  
  67. End Sub
  68.  
Any help gratefully appreciated.

Thanks
Sandra
Sep 5 '07 #1
4 2133
barry07
47 New Member
Hi Sandra,
The simplest solution is to modify the query (qryName) so it selects all the jobs you need instead of just one. You will also need to modify the PrintOut statement as follows:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.PrintOut acPrintAll, , , , , Yes
I can't guarantee that this will necesssarily print one job per page. That's another day's work. Have you looked at Access Reports?
Sep 5 '07 #2
JKing
1,206 Recognized Expert Top Contributor
Hi there, I dont quite understand what you're doing here.

First you delete the temporary table, then open a query, open a form and start printing.

Is the query the form's recordsource? Also you don't need to open a query to use it as a recordset.

I believe the multiple copies of the same record is caused by printing the same page numbers over and over. No where in your code are you changing the page numbers or changing the records of the form.

Off the top of my head I think either a) incrementing the page numbers would help or b) filtering the form to equal each specific record print then move to the next record.
Sep 5 '07 #3
ske
2 New Member
Thanks for replying.

I can get the form to print out fine without the IF statements around the printout statement. The reference in the IF statement seems to be the problem.

I know the statements at the beginning are a bit round the houses but I can sort that out later. Unfortunately I need to print out each record one or two sided depending on whether SpecificRiskAss field is ticked.
Sep 6 '07 #4
JKing
1,206 Recognized Expert Top Contributor
You have a variable i that doesn't seem to be used. Upon adding the if statements did you accidentally remove it from the Docmd.PrintOut parameters? Instead of the 1 I think you may actually want to be using the i integer you've created.
Sep 6 '07 #5

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

Similar topics

6
17975
by: Michael Goerz | last post by:
Hi, I'm trying to write a loop that cycles through all the records. This I use for doing comparisons between all records or to export all records to a text file. I'm using the following code: '************************************* .... 'Finding the count of all records
6
2244
by: John | last post by:
Hi, I have simple database based on 3 tables. Relationship is 'one to many' between table 1 and 2, also between 2 and 3 table'one to many'. I have made form where I enter data in all 3 tables. Form has 2 subform based on relationships. I want to make report to print data which is shown on form. I want to print only data from form, not whole records from tables. Does anyone knows how to do this? I have tried with report based on query,...
4
4719
by: Sami | last post by:
I hope someone will tell me how to do this without having to do any VB as I know nothing in that area. I am a rank beginner in using Access. I have created a database consisting of student athletes.  I have now learned how to join two different tables in a query so that I might generate a report. Specifically, student athletes at a community college are required to graduate with an AA or AS degree.  Consequently, various steps are in...
6
2794
by: MS | last post by:
Access 97 here. I want a simple way to "lock" certain records on a form. Some records remain "live" until all data is available which happens over time. When all the fields are complete, I want the record to be able to be "locked", or intentionally unlocked. I thought of having a check box called "chkedit" that can be clicked when the data entry for the record is complete. I have the following code in the OnCurrent event for the...
1
2935
by: Earl Anderson | last post by:
Using WinXP & AccessXP, I'd like to automatically have the records that I've just printed in a report automatically updated to have the 'print date & time' immediately inserted into a 'Date/Time' field in the table of all of the 'just printed' records. The crude way would be to run an Update Query immediately before or immediately after printing on those records in the report, but how would I have this done automatically when hitting the...
3
1427
by: MattB | last post by:
I have a RadioButtonList then binds to a DataTable in my Web Form. The DataTextField is called "descrip" and I want to bind only records that don;t have an empty descrip field. My initial approach was to loop through the rows collection, test each row's descrip field and if it's empty delete it. That didn;t work because I guess you can't delete from a collection you are currently looping on (makes sense). I've got some other ideas,...
20
3055
by: Stewart Graefner | last post by:
Here is a chunk of code that works for an individual record. It evaluates dates and checks or unchecks boxes as it goes along. It may not be pretty but it works. What my problem is that I need it to evaluate all the records(200+) in my db and change those which need changing. Having to do it individually would defeat the purpose of developing this code. What I would like to be able to do is either 1. Open the db push a button and all the...
1
2947
by: projectjakecs | last post by:
Hi, I am working on a ms access database and I am having trouble using a form to create new records in an associative table. Here is the breakdown of my database: Main Table - Computer Primary Key - ComputerID (AutoNumber) ComputerName
2
3322
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a certain number of them. Firstly I identify all the parent records that have the requird number of child records and insert them into the result table.
0
8481
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7441
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6234
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5702
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2817
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 we have to send another system
2
1814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.