Solved

Printing

Posted on 2000-05-18
2
137 Views
Last Modified: 2010-05-02
I'm relatively new at V.B 6 and would appreciate any
help I can get!

I'm trying to print text from txt1 to my "Canon BJC-5100" printer.
When the user makes  selections in the Font dialog box,
the selected font properties (Color, FontBold, Italic, Underline,
Strikethru, Name, Size) are properly shown on the screen.
But the text are printed out without the selected font properties
except FontSize property.

Can anyone help me to correct my errors?

Private Sub Command1_Click ()
    ' Set Cancel to True.  
    CommonDialog1.CancelError = True  
    On Error GoTo ErrHandler  
    'Set the Flags property.  
    CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
    ' Display the Font dialog box.  
    CommonDialog1.ShowFont    
    ' Set text properties according to user's  selections.  
    txt1.Font.Name = CommonDialog1.FontName  
    txt1.Font.Size = CommonDialog1.FontSize  
    txt1.Font.Bold = CommonDialog1.FontBold  
    txt1.Font.Italic = CommonDialog1.FontItalic  
    txt1.Font.Underline = CommonDialog1.FontUnderline  
    txt1.FontStrikethru = CommonDialog1.FontStrikethru  
    txt1.ForeColor = CommonDialog1.Color  
  Exit SubErrHandler:  
    ' User pressed Cancel button.  
Exit Sub
End Sub

Private Sub mnuFilePrint_()
Dim BeginPage, EndPage, NumCopies, Orientation, i
     ' Set Cancel to True.
     CommonDialog1.CancelError = True
     On Error GoTo ErrHandler
     ' Display the Print dialog box.
     CommonDialog1.ShowPrinter
     ' Get user-selected values from the dialog box.
     BeginPage = CommonDialog1.FromPage
     EndPage = CommonDialog1.ToPage
     NumCopies = CommonDialog1.Copies
     Orientation = CommonDialog1.Orientation
     For i = 1 To NumCopies
     ' Put code here to send data to your printer.
                     
    Printer.ForeColor = txt1.ForeColor
    Printer.FontBold = txt1.FontBold
    Printer.FontItalic = txt1.FontItalic
    Printer.FontUnderline = txt1.FontUnderline
    Printer.FontStrikethru = txt1.FontStrikethru
    Printer.FontSize = txt1.FontSize

   Printer.CurrentX = 1247
   Printer.CurrentY = 2438
   Printer.Print txt1.Text

I would really appreciate any help that anyone could offer.

Thank you.

CSTANG
0
Comment
Question by:CSTANG
2 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 2820510
All you need to do is replace the existing font settings that you have with the following:

'    Printer.ForeColor = txt1.ForeColor
'    Printer.FontBold = txt1.FontBold
'    Printer.FontItalic = txt1.FontItalic
'    Printer.FontUnderline = txt1.FontUnderline
'    Printer.FontStrikethru = txt1.FontStrikethru
'    Printer.FontSize = txt1.FontSize

   Set Printer.Font = txt1.Font

   Printer.CurrentX = 1247
   Printer.CurrentY = 2438
   Printer.Print txt1.Text

Try it and see!
0
 
LVL 7

Accepted Solution

by:
BarryTice earned 5 total points
ID: 2821386
Don't forget to put

    Printer.EndDoc

at the end of everything to make sure it all goes through and frees up the printer properly.
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

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 177
Vb.net 2008 2 56
Paint/Redraw window while dragging 16 68
Copy a row 12 58
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now