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

Easy Printing Question...

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!

econy1
0
econy1
Asked:
econy1
  • 5
  • 2
1 Solution
 
csalvesCommented:
Hello,

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

regards,
0
 
econy1Author Commented:
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
    frmPrint.Hide
End Sub

Private Sub cmdPrint_Click()    
    For Each printersAvail In Printers
        If printersAvail.DeviceName = cboPrinter.Text Then
            Set Printer = printersAvail
            PrintThis
        Exit For
        End If
    Next          
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
    Next
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!!!

0
 
csalvesCommented:
Hello,

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.

bye,
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
econy1Author Commented:
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!


0
 
econy1Author Commented:
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

HELP?!?!?!?!
0
 
econy1Author Commented:
....one more thing...
how do i set the margins for my page???
0
 
econy1Author Commented:
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!
thanks!!!
0
 
MirkwoodCommented:
Bought This Question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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