Solved

vb Print

Posted on 2009-07-14
5
282 Views
Last Modified: 2013-12-26
How to add code below to increase the font of  len(trim(h.h1)) ?
I just want to increase the font of the heading of my printing. Please help me!
Thanks!
Private Sub OfficialReceipt_LOCAL(trxno As String)

Dim rs      As DAO.Recordset

Dim STR     As String

Dim i       As Double

Set rs = dbLocal.OpenRecordset("SELECT * FROM DETAILS WHERE DOCNO='" & saveDocNo & "' ORDER BY ROWNO ASC")

        Open OpenPort_ For Output As #1

        

        i = Len(Trim(H.H1))

        i = i \ 2

        i = 20 - i

        If i = 20 Then

        Else

            STR = Space(i) & Trim(H.H1)

            Print #1, STR

        End If

        Print #1, "Customer : " & Trim(Setmeup(0))

        If i = 20 Then

        Else

            STR = Space(i) & Trim(H.H6)

            'Print #1, STR

        End If

            Print #1, String(40, "_")

            Print #1, "DESCRIPTION   QTY      PRICE      AMOUNT"

            Print #1, String(40, "-")

            Set rs = Nothing

            For i = 0 To NoLineFeed

            Next

            Close #1

Set rs = Nothing

End Sub

Open in new window

0
Comment
Question by:Whing Dela Cruz
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 24849243
The problem as I see it is that you are attempting to print to a file.  Printing to a file basically limits you to text only.

On the other hand, if you print to the VB printer (using "Print" rather than "Print #1"), then you will be printing through the print driver.  In this case, the VB printer object has properties such as Font settings that allow you to control the current Font used by the print driver.

But as long as you continue to print to a file, the only way to change the font is to know what printer the file will eventually be printed on and used the Esc codes that that printer uses to change the font properties.  But that would mean your output would only be valid for that printer.  On the other hand, that's a part of the purpose for Windows and things like the VB Printer object and print drivers... so that a programer can print to the generic windows printer and the output will be like you want regardless of the printer printed to (within the limits of the print driver for that printer).
0
 

Author Comment

by:Whing Dela Cruz
ID: 24849413
Hi!  I attemp to use the code below just to insest  my idea inspite of the comment you had just sent to me but i do not know if this scenario can solved my problem. When i try this, the heading will not locate to upper portion but its position will always display below. In my code, Can I assign the heading to the top side of the report? If yes, please tell me how! Thanks    
Private Sub OfficialReceipt_LOCAL(trxno As String)

    Set PRN = Printer

    PRN.ScaleMode = 2

    PRN.CurrentX = 30: PRN.CurrentY = 15

    Dim fnt As New StdFont

    fnt.Name = "Verdana": fnt.Size = 14: fnt.Bold = True

    Set PRN.Font = fnt

    PRN.Print "My Heading"
 

Dim rs      As DAO.Recordset

Dim STR     As String

Dim i       As Double

Set rs = dbLocal.OpenRecordset("SELECT * FROM DETAILS WHERE DOCNO='" & saveDocNo & "' ORDER BY ROWNO ASC")

        Open OpenPort_ For Output As #1

        Print #1, ""

        Print #1, ""

        Print #1, "" & PRN.print; "My heading"

        Print #1, "Customer : " & Trim(Setmeup(0))

        If i = 20 Then

        Else

            STR = Space(i) & Trim(H.H6)

            'Print #1, STR

        End If

            Print #1, String(40, "_")

            Print #1, "DESCRIPTION   QTY      PRICE      AMOUNT"

            Print #1, String(40, "-")

            Set rs = Nothing

            For i = 0 To NoLineFeed

            Next

            Close #1

Printer.EndDoc

Set rs = Nothing

End Sub

Open in new window

0
 

Author Comment

by:Whing Dela Cruz
ID: 24849427
Sorry, the  line 17 is not working..
0
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 500 total points
ID: 24850696
Use the properties 'Printer.CurrentX' and 'Printer.CurrentY' to position the cursor on the logical print page.  I believe dimensions are in twips (1440 twips = 1 inch) and retative to the printable margins of the page (not the edge of the page).

This means you might need to update CurrentX and CurrentY at the start of each line, and again you need to be using Print ... rather than Print #1...

BTW, to modify the Font, you can use Printer.Font  The main properties of the font you are likely to play with are:
Printer.Font.Bold
Printer.Font.Size
Printer.Font.Italic
Printer.Font.Underline
Printer.Font.Name   (which font, Arial, Times New Roman, Courier, etc).

...

Ok, now that I've taken a closer look at your example, it looks like you are getting closer and you're using this commands.  Here's my suggestion until you get a handle on how this is going to work, use the Printer object directly (rather than assigning it to PRN) and completely get rid of 'Print #1" and PRN.Print.
Private Sub OfficialReceipt_LOCAL(trxno As String)

    Printer.ScaleMode = 2

    Printer.Font.Name = "Verdana"

    Printer.Font.Size = 14

    Printer.Bold = True

    Printer.CurrentX = 30: Printer.CurrentY = 15

    Print "My Heading"

 

Dim rs      As DAO.Recordset

Dim STR     As String

Dim i       As Double

Set rs = dbLocal.OpenRecordset("SELECT * FROM DETAILS WHERE DOCNO='" & saveDocNo & "' ORDER BY ROWNO ASC")

    Printer.CurrentX = 30

    Printer.CurrentY = 30

    Print "Customer : " & Trim(Setmeup(0))

    Print String(40, "_")

    Print "DESCRIPTION   QTY      PRICE      AMOUNT"

    Print String(40, "-")

    Set rs = Nothing

    For i = 0 To NoLineFeed

    Printer.CurrentX = 30

    Printer.CurrentY = 30 + 15* i

    Print RS.Desc

    Next

    Printer.EndPage

    Printer.EndDoc

Set rs = Nothing

End Sub

Open in new window

0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 31603206
Thank you so much to you. the code is working. More power! Thanks!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now