?
Solved

Automate printing a list from the database with a VB Form

Posted on 2009-07-14
3
Medium Priority
?
149 Views
Last Modified: 2012-05-07
I have a form where I enter data and it goes to an SQL database.  I use the code below to place the data in the db.

Now here's my problem.  I want to bring the data back to the form so that I can print it and get a hard copy sheet for each student we have.  The problem is I would have to retrieve each record one by one into the form and then print.

Is there a quicker way to do this to automate the process or not?
esql = "select * from tblRegistration"
        rec.Open (esql), conn, adOpenDynamic, adLockOptimistic
        rec.AddNew
        
        rec.Fields(1) = frmRegistrationTitleXX.Text1
        rec.Fields(2) = frmRegistrationTitleXX.Text2
        rec.Fields(3) = frmRegistrationTitleXX.Text3
        rec.Fields(4) = frmRegistrationTitleXX.Text4
        rec.Fields(5) = frmRegistrationTitleXX.Text5
        If Not Text6 = "(M.I.)" Then
            rec.Fields(6) = frmRegistrationTitleXX.Text6
        End If
        rec.Fields(7) = frmRegistrationTitleXX.Text7
        rec.Fields(8) = frmRegistrationTitleXX.Text8
        rec.Fields(9) = frmRegistrationTitleXX.Text9
        rec.Fields(10) = frmRegistrationTitleXX.Text10
        rec.Fields(11) = frmRegistrationTitleXX.Text11
        rec.Fields(12) = frmRegistrationTitleXX.Text12
        rec.Fields(13) = frmRegistrationTitleXX.Text13
        rec.Fields(14) = frmRegistrationTitleXX.Text14
        rec.Fields(15) = frmRegistrationTitleXX.Text15
        rec.Fields(16) = frmRegistrationTitleXX.Text16
        rec.Fields(17) = frmRegistrationTitleXX.Text17
        
        rec.Fields(18) = frmRegistrationTitleXX.Check1
        rec.Fields(19) = frmRegistrationTitleXX.Check2
        rec.Fields(20) = frmRegistrationTitleXX.Check3
        rec.Fields(21) = frmRegistrationTitleXX.Check4
        rec.Fields(22) = frmRegistrationTitleXX.Check5
        rec.Fields(23) = frmRegistrationTitleXX.Check6
        rec.Fields(24) = frmRegistrationTitleXX.Check7
        rec.Fields(25) = frmRegistrationTitleXX.Check8
        rec.Fields(26) = frmRegistrationTitleXX.Check9
        rec.Fields(27) = frmRegistrationTitleXX.Check10
        rec.Fields(28) = frmRegistrationTitleXX.Check11
        rec.Fields(29) = frmRegistrationTitleXX.Check12
        rec.Fields(30) = frmRegistrationTitleXX.Check13
        rec.Fields(31) = frmRegistrationTitleXX.Check14
        rec.Fields(32) = frmRegistrationTitleXX.Check15
        rec.Fields(33) = frmRegistrationTitleXX.Check16
        rec.Fields(34) = frmRegistrationTitleXX.Check17
        rec.Fields(35) = frmRegistrationTitleXX.Check18
       
        
        rec.Fields(36) = frmRegistrationTitleXX.Combo1
        rec.Fields(37) = frmRegistrationTitleXX.Combo2
        rec.Fields(38) = frmRegistrationTitleXX.Combo3
        rec.Fields(39) = frmRegistrationTitleXX.Combo4
        rec.Fields(40) = frmRegistrationTitleXX.Combo5
        rec.Fields(41) = frmRegistrationTitleXX.Combo6
        rec.Fields(42) = frmRegistrationTitleXX.Combo7
        rec.Fields(43) = frmRegistrationTitleXX.Combo8
        rec.Fields(44) = frmRegistrationTitleXX.Combo9
        rec.Fields(45) = frmRegistrationTitleXX.Combo10
        
        rec.Fields(46) = frmRegistrationTitleXX.Text18
        rec.Fields(47) = frmRegistrationTitleXX.Text19
        rec.Fields(48) = frmRegistrationTitleXX.Text20
        rec.Fields(49) = frmRegistrationTitleXX.Text21
        rec.Fields(50) = frmRegistrationTitleXX.Combo11
        
        If Not rec.EOF Then rec.MoveNext
        rec.Close

Open in new window

0
Comment
Question by:al4629740
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:cool12399
ID: 24866497
Hi,

If you mean you want to print the actual windows 'form', then no, not really, there is not really a quicker process. (You can, but it might be a bit convoluted).

If however you want to control the formatting, etc, look at the printer object.

I.e.,

printer.print line1data
printer.print line2data
printer.print line3data

etc, etc

If you do this, you can iterate through _x_ number of records, and simply print them all at once.
0
 

Author Comment

by:al4629740
ID: 24866504
printer.print line1data

Can you explain this code in laymens terms?
0
 
LVL 10

Accepted Solution

by:
cool12399 earned 2000 total points
ID: 24868936
Printer is your your printer, line1data is the text you want to print.

So:

Printer.newpage
Printer.x = 100
Printer.y = 100
Printer.print "Hi there, what's new?"
Printer.enddoc

Will print the text "Hi there, what's new?" at location 100,100 (twips) on your paper.
Experiment with the locations to figure out the spacing, and you are set.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question