Easy Printing Question...

Posted on 1998-11-05
Last Modified: 2010-04-30
I am a novice VB programmer, and have what i think will be a simple question about printing.
I have a main form for my program.  once print from the file menu is selected, i have another form come up which has a combo box for the user to select which printer they wish to use.  then i have two buttons on the print form (print and cancel).  once print is selected, i want to set the selected printer from the combo box to the printer that will be used to print...  also, when print is selected, i want to call a function (PrintThis) which is in the main form's code window.  This PrintThis function will contain all the code to send the necessary information to the printer (which has been selected).

Thanks for the help.  Hope this isn't too confusing!

Question by:econy1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2

Accepted Solution

csalves earned 50 total points
ID: 1443441

change your Private function in main form to Public and then call it. IF it doesn't work you can refer the MainForm.Function.


Author Comment

ID: 1443442
my print function in the main form is written like this:
Public Sub PrintThis()
End Sub

Is this what you are talking about?  can i now call PrintThis from the code window from any form (like my Print form)?

Also, can you help me out with the code in my Print form?  because it's not working.  this is what i have:

Option Explicit

Dim X As Integer
Dim selectedPrinter As String
Dim printersAvail As Printer

Private Sub cmdCancel_Click()
    'close print window if cancel button is pressed
End Sub

Private Sub cmdPrint_Click()    
    For Each printersAvail In Printers
        If printersAvail.DeviceName = cboPrinter.Text Then
            Set Printer = printersAvail
        Exit For
        End If
End Sub

Private Sub Form_Load()
    'add all available printers to printer combo box
    For X = 0 To Printers.Count - 1
        cboPrinter.AddItem Printers(X).DeviceName
End Sub

when cmdPrint is clicked, i want whatever printer that's been selected in cboPrinter to be set as the printer, but i'm not sure how to do this!

Thanks a lot!!!


Expert Comment

ID: 1443443

Yes you can call your PrintProcedure from anywhere in project.

I've replicated your code and it works fine.
Don't forget to refer the form.object if you want to use information of another form diferent from the current.

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

ID: 1443444
okay, here's what i've done:

the print functin (printThis()) is public, but when i call it from the print form i still have to write frmWriteThis.printThis - but that now seems to be working.

when i click on print, though, the Windows printer icon shows up in the task bar.  when i click on it, it tells me that the printer status is "spooling" and it stays there - and never prints.  then when i exit my VB program, i get a Microsoft Visual Basic Print Error!


Author Comment

ID: 1443445
okay, now something a bit different is happening.
when i select my local printer, it prints.
when i select a printer on the network, it just says "spooling"

but... even when i get it to print on my local printer, even though i have set
    Printer.FontName = "Arial"
    Printer.FontSize = 16
it is still printed out in Courier as size 12


Author Comment

ID: 1443446 more thing...
how do i set the margins for my page???

Author Comment

ID: 1443447
okay, some more progress...  the font and fontsize now prints correctly.  if you could just suggest how to set the margins, i'll award you the points!
LVL 13

Expert Comment

ID: 1443448
Bought This Question.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

734 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