• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

vb Print

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
Whing Dela Cruz
Asked:
Whing Dela Cruz
  • 3
  • 2
1 Solution
 
HooKooDooKuCommented:
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
 
Whing Dela CruzAuthor Commented:
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
 
Whing Dela CruzAuthor Commented:
Sorry, the  line 17 is not working..
0
 
HooKooDooKuCommented:
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
 
Whing Dela CruzAuthor Commented:
Thank you so much to you. the code is working. More power! Thanks!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now