Solved

vb Print

Posted on 2009-07-14
5
285 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

23 Experts available now in Live!

Get 1:1 Help Now