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 programmatically.
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: -
Private Sub cmdOK_Click()
-
On Error GoTo Err_cmdOK_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
Dim db As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim strdate As String
-
Dim strRanger As String
-
Dim qryName As String
-
Dim tblName As String
-
Dim strSQL As String
-
Dim i As Integer
-
-
stDocName = "frmJobSheetTrimble"
-
tblName = "tblTempJobSheet"
-
qryName = "qryJobSheetByDate"
-
-
strSQL = "delete from tblTempJobSheet"
-
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL strSQL
-
-
DoCmd.OpenQuery qryName, acViewNormal ' This creates the temporary table to print the record from.
-
-
Set db = CurrentDb()
-
Set rst = db.OpenRecordset("tbltempJobSheet")
-
-
i = 0
-
MsgBox "You are about to print" & " " & Count & " " & "records.", vbOKCancel
-
-
DoCmd.OpenForm stDocName, , , , , acWindowNormal
-
-
rst.MoveFirst
-
Do While Not rst.EOF
-
i = i + 1
-
If rst![SpecificRiskAss] = True Then
-
DoCmd.PrintOut acPages, 1, 2, , , Yes
-
-
End If
-
-
If rst![SpecificRiskAss] = False Then
-
DoCmd.PrintOut acPages, 1, 1, , , Yes
-
End If
-
-
rst.MoveNext
-
Loop
-
-
rst.close
-
-
Set rst = Nothing
-
Set db = Nothing
-
-
DoCmd.SetWarnings True
-
DoCmd.close acForm, stDocName
-
-
stDocName1 = "frmJobSheetPrinted"
-
DoCmd.OpenForm stDocName1, , , stLinkCriteria
-
-
Exit_cmdOK_Click:
-
Exit Sub
-
-
Err_cmdOK_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdOK_Click
-
-
End Sub
-
Any help gratefully appreciated.
Thanks
Sandra
4 2118
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: - 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?
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
...
|
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....
|
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...
|
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...
|
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'...
|
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...
|
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...
|
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...
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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: 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...
| |