473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to print all records in recordset

91
I have a subform that displays all of the invoices for the day selected. There is a "Print all" button (code below) that should print all the records in the recordset. I cant figure out why it does not work, but it appears to be only printing one record.

Does anyone have any ideas?

Expand|Select|Wrap|Line Numbers
  1. Dim rs As Recordset
  2.  
  3.     Set rs = frmsubAdminEdit.Form.Recordset
  4.  
  5.     rs.MoveFirst
  6.     Do Until rs.EOF
  7.  
  8.         If rs(7) > 0 Then
  9.  
  10.             DoCmd.OpenReport "rptInvoice", acViewNormal, , "OrderID=" & rs(0), , False
  11.             rs.Edit
  12.             rs(6) = -1
  13.             rs.Update
  14.  
  15.         End If
  16.  
  17.         rs.MoveNext
  18.  
  19.     Loop
  20.  
  21.     Set rs = Nothing
  22.  
  23.  
May 13 '10 #1
14 14435
NeoPa
32,556 Expert Mod 16PB
I would say only that rs should be declared as DAO.Recordset, as otherwise it is ambiguous. Also, rs(6) & rs(7) are entirely meaningless in your uncommented code.

The only things that appear questionable to my limited understanding is that you set rs(6), but check rs(7). Also you set to -1 but check for > 0.
May 14 '10 #2
matt753
91
Thanks

Here is the updated code:

Expand|Select|Wrap|Line Numbers
  1.     Dim rs As DAO.Recordset
  2.     Set rs = frmsubAdminEdit.Form.Recordset
  3.  
  4.     If rs.RecordCount > 0 Then
  5.         rs.MoveLast
  6.         rs.MoveFirst
  7.  
  8.         Do Until rs.EOF
  9.             MsgBox (rs(0))   'show id of current record
  10.  
  11.             DoCmd.OpenReport "rptinvoice", acViewNormal, , "OrderID=" & rs("OrderID")
  12.             rs.Edit
  13.             rs.Update
  14.  
  15.             rs.MoveNext
  16.         Loop
  17.  
  18.         rs.Close
  19.         rs = Nothing
  20.  
  21.     Else
  22.         MsgBox ("No records to print")
  23.     End If
  24.  
It still only prints the first record though. If I comment out the DoCmd.OpenReport line it will go through all the items fine, but if its there it will only do the first.

Also do I need the rs.Edit and rs.Update if im not making any changes to the recordset?
May 14 '10 #3
Jim Doherty
897 Expert 512MB
@matt753
Hi,

Where are you closing the report in order for it to re-open again to catch the next value in the loop? You open a report to show either a single record or pass criteria to it show a sequence of records surely. Should you not be opening a report once?
May 14 '10 #4
matt753
91
I'm not sure, the report doesnt actually open on the screen, that is just used to print the one invoice. Are you saying I need to close the report so that the loop will go to the next value?

I know this code was working at one point, but im not sure how much it has been changed since then. I'm not the one who originally wrote it, just trying to fix it.
May 14 '10 #5
Jim Doherty
897 Expert 512MB
@matt753
Sorry Matt misunderstood quick glance thought you were previewing as opposed to printing directly I,ll will replicate what you have and test it here
May 14 '10 #6
matt753
91
Thanks

Yea i'm not sure why it prints by just opening the report (theres no code for it in the report). Is there something else attached somewhere that tells it to print?
May 14 '10 #7
Jim Doherty
897 Expert 512MB
@matt753
Matt your code is fine ...have no problems here. The acViewNormal constant section of the command section prints the report. (I mistakenly thought earlier you were previewing) hmm strange one. You sure you havent got any filtration criteria sneaking in there thats setting the reports record behaviour somehow? nothing in the reports code?
May 14 '10 #8
matt753
91
Is there another way I could code it maybe? Such as having it individually opening and closing each one and printing it or something?

I never actually let it print the one before, I just tried it and it doesnt even do the one. The small print window flashes for a second but it never actually gets sent to the printer. Not a printer problem either, tried this on different computers.
May 14 '10 #9
Jim Doherty
897 Expert 512MB
@matt753
Sounds really strange experience you are having there Matt because everything works out code wise. You could try opening and closing the report each time in the loop (although there is no need to of course). the command for that is this

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acReport, rptInvoice, acSaveNo
Check the reports Filter property and FilterOn property see what they are saying are they blank?

The usual maintenance options you might look at - repair and compact decompiling and recompiling the database. Am afraid without looking directly at this everything is a shot in the dark!
May 14 '10 #10
matt753
91
I tried putting the closing code in there, same thing still happens unfortunately.


Check the reports Filter property and FilterOn property see what they are saying are they blank?
I have the subform (which the recordset is based from) filtered to only show the records for the current date, so the filteron property is true and the filter property is being used. The recordset only contains these items though, and the loop is hitting each item correctly without that code. (I tested having a messagebox appear with each id# and it works fine)



Is there any other methods for printing a report? I tried:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.PrintOut acPrintAll
but that just prints a screenshot of the form. It will send one print item for each recordset item, and show the messageboxes mentioned above for testing with each id#, so that part is working correctly in the loop.

I see theres a "DoCmd.RunCommand acCmdPrint" could this be used?
May 14 '10 #11
NeoPa
32,556 Expert Mod 16PB
You don't need the Edit/Update.

I suspect that something is not right about your OpenReport command. [OrderID] may be alphanumeric for instance, then the filter would be wrong.

I would use the debugging tools to see what's happening more clearly (See Debugging in VBA).
May 14 '10 #12
matt753
91
I got it to work, turns out there was an error in the code when the report was opening. There was an if statement seeing if a checkbox was checked but apparenly you cant do that from a form. The error didnt display at all when this code was ran, only when it was opened manually.
May 17 '10 #13
Jim Doherty
897 Expert 512MB
@matt753
Thanks for posting back your result Matt :-)
May 17 '10 #14
matt753
91
Thanks for all the help guys
May 17 '10 #15

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

Similar topics

22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
13
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
0
by: rajaaryan44 | last post by:
in my project i m using data environment to peint the records . but i cannot get the required print as i have to go and manuaaly set the printer settings . its very tiresome . . i m using these...
2
by: Tom Clavel | last post by:
Scratching my head. I am using the filter property on a combo box .AfterUpdate event to get to a single client record. This is causing a some strange behavior: As I enter a subform, I get a no...
1
by: lee | last post by:
Could anyone link me to info on this: I have to print-out an access DB. Some of the fields have a few characters in them, and some fields in the same record could have a small paragraph of...
11
by: fieldling | last post by:
I have a query which I view through a form. Due to problems with the label wizard printing to a dot-matrix printer I have some code to print out a single label when a command button is clicked. This...
2
by: hackmagic | last post by:
Hi, i have a form that normally has a Recordset containing only one record bound to it. i have replaced the navigation buttons with my own and the 'New Record' button assigns an empty Recordset...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
1
tsubasa
by: tsubasa | last post by:
I have a recordset that I am displaying via an ASP. On the web page each record has a textbox next to it, so the user can enter a number for the amount of times that record will need to be displayed...
0
it0ny
by: it0ny | last post by:
Hi guys, thanks I am fairly new to this forum so I hope I chose the right place to post this question. I try to make my program printout a deposit's report. I created a class to store the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.