Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Printing Problem using VB

Posted on 2003-03-04
Medium Priority
Last Modified: 2010-05-18
Hi, guys,

What I need to do is like a check printing job, i want to pull out information from database, then fill those information into some type of format, then print it with specified check papers, which is 3 checks per page.

I try to use the scanned check as the background image of the VB Form to make those line aligning and formating issues much easier. The problem is, the largest height of a Form is 12288, which is smaller than a letter size paper.
when i use the Form1.PrintForm method, it can't fit the letter size paper.

Can i increase the height of a Form, or is there other way to print a well-organized page from a Form?

I tried some other ways also:
1. I tried to output all infomation into a plain text file, then print it. The problem is then i can't insert a picture of company logo in the text file, and the formating is really a pain.

2. I tried to use the Printer object, which is like:

Printer.Font = "Arial"
Printer.FontSize = 10
Printer.Print Tab(10); "a"; Tab(30); "b"; Tab(50); "c"

This allows me not worry about the height of a form, nor the picture printing issue. However, it gave me a real hard time to align the info to the pre-specified column, it might print on the lines, not above it.
Anyway to have better control on Printer object? For example, specify the line spacing?

3. I saw there is an example in MSDN network called "Tip 100: Printing a Form Multiple Times on One Page"
the link is as follows

I feel like it's the solution for me, cause i need to print 3 checks a page. Unfortunately, even I copied the code and followed the instructions, the program ended up with "Run-time Error '6': Overflow" at the line of
"X = SetStretchBltMode(Form2.hDC, 3)", which i have no idea what is that all about.

Sorry for this long question. Hope this beginner question won't take too much of your time. I just tried any possible way to get my work done. Any help, any approach will be a big help to me.


Question by:WillatSA

Accepted Solution

JoaTex earned 200 total points
ID: 8068542

This is a litle example where you can have control on left and right margins, and space between lines, With top Name. Try and adapted to your needs.

Option Explicit
Dim Provis As String    'String Text1
Dim N                   'Counter
Dim LeftSide            'Margin Left
Dim RightSide           'Margin Right
Dim TopSide             'Top Title Position
Dim Spac                'Space between Lines
Dim BottomSide          'Position Ens Page
Dim Position            'Flag Control New Line

Private Sub PrintCmd_Click()
    LeftSide = 1000
    RightSide = 9000
    Spac = 250
    BottomSide = 15000
    Title                  'Title
    Provis = Text1.Text     'Transfer Text1
    For N = 1 To Len(Provis)    'Run Each Character of String
    Printer.Print Mid(Provis, N, 1);    'Print Character
    If Printer.CurrentY > Position + 32 And Mid(Provis, N, 1) <> Chr(13) Then 'Control CRLF
        Printer.CurrentX = LeftSide
        Printer.CurrentY = Position + Spac  'New Line
        Position = Printer.CurrentY
    End If
    If Printer.CurrentX > RightSide And Mid(Provis, N, 1) = " " Then 'Control End Line
        Printer.CurrentY = Position + Spac  'New Line
        Position = Printer.CurrentY
        Printer.CurrentX = LeftSide     'Control Left Margin
    End If
    If Printer.CurrentY > BottomSide Then   'Control End Page
    End If
    Next N
    Printer.EndDoc      'Close Print Document
End Sub

Private Sub Title()
    TopSide = 2000
 Printer.FontName = "Arial Black"      'Config Title
    Printer.FontSize = 14
    Printer.FontBold = True
    Printer.CurrentY = TopSide     'Position Title
    Printer.CurrentX = LeftSide + 3000
    Printer.Print "Print Text Box"
    Printer.FontName = "Arial"
    Printer.FontSize = 12       'Change Size Plain Text
    Printer.FontBold = False
    Printer.CurrentY = TopSide + 1000
    Position = Printer.CurrentY
    Printer.CurrentX = LeftSide     'margin LeftSide Size
End Sub

Expert Comment

ID: 8068555
It should be a simple matter to layout the check on the page using VB's printer object (i.e. Printer.CurrentX, Printer.CurrentY, Printer.Print, etc.).

Author Comment

ID: 8072672
thanks, i am now working with the printer object... though it's really a print-and-error process.

Expert Comment

ID: 8900691
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

564 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