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

VB 6.0 Report, User Printer Selection

I have an APP with several VB 6.0 reports, one of which is called 'rptMainInfo'.  I currently have logic that allows the user to select whether they want to view the report on the screen or send it to the printer.  Based on thier response the following code accomplishes that:

With rptMainInfo
  Set .DataSource = rsMainInfo
  .DataMember = rsMainInfo.DataMember
  DoEvents
    If PrintEm = True Then
        .PrintReport
    Else
        .Show vbModal
    End If

End With

If the print option is selected, the report is sent directly to the default printer without giving the user any chance to direct it elsewhere.  The user now wants the ability to decide which printer to send the hard copy output.  Showing them the standard windows printer selection box would be ideal if possible.  If not, are there other options?  Any ideas on how to accomplish this within the program flow?

I also have some output being generated by the Printform command.  Is there anyway to allow them to select where they want to direct that output?
0
mlcktmguy
Asked:
mlcktmguy
1 Solution
 
Mikal613Commented:
you can add your own combo Box  and do this

Private Sub LoadPrinters()

Dim P as Printer

 For Each P In Printers
        CMB.Additem  P.DeviceName & " on " & P.Port =
  Next

End sub

0
 
vinnyd79Commented:
Here is an example that uses a combobox:

Private Sub Form_Load()
LoadPrinters
End Sub

Private Sub Combo1_Click()
Set Printer = Printers(Combo1.ListIndex)
End Sub

Private Sub LoadPrinters()
Dim pr As Printer

For Each pr In Printers
   Combo1.AddItem pr.DeviceName
Next pr
Combo1.Text = Printer.DeviceName

End Sub
0
 
Mikal613Commented:
When you print  you then Set the printer to what he slelected


dim P as printer
For Each P In Printers
        If P.DeviceName & " on " & P.Port = cboPrinters.Text Then
            Set Printer = P
            Exit For
        End If
    Next
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.

 
Mikal613Commented:
else

add a Common Dialog

and do showprinter
0
 
Shiju SasidharanAssoc Project ManagerCommented:
hi
try this
'----------------------------------------
With rptMainInfo
  Set .DataSource = rsMainInfo
  .DataMember = rsMainInfo.DataMember
  DoEvents
    If PrintEm = True Then
'>> Change made here..

        .PrintReport True
    Else
        .Show vbModal
    End If

End With
'-----------------------------

;-)
Shiju

0
 
mlcktmguyAuthor Commented:
when I put in the command ShowPrinter I get a compile error.  The ShowPrinter command is highlighted and the message is:

Sub or Function Not Defined

0
 
Mikal613Commented:
Did you add a Commn Dialog ??
0
 
Mikal613Commented:
CommonDialog Control
           

The CommonDialog control provides a standard set of dialog boxes for operations such as opening and saving files, setting print options, and selecting colors and fonts. The control also has the ability to display help by running the Windows Help engine.

Syntax

CommonDialog

Remarks

The CommonDialog control provides an interface between Visual Basic and the routines in the Microsoft Windows dynamic-link library Commdlg.dll. To create a dialog box using this control, Commdlg.dll must be in your Microsoft Windows SYSTEM directory.

You use the CommonDialog control in your application by adding it to a form and setting its properties. The dialog displayed by the control is determined by the methods of the control. Atrun time, a dialog box is displayed or the help engine is executed, when the appropriate method is invoked; atdesign time, the CommonDialog control is displayed as an icon on a form. This icon can't be sized.

The CommonDialog control can display the following dialogs using the specified method.

Method Dialog Displayed
ShowOpen Show Open Dialog Box
ShowSave Show Save As Dialog Box
ShowColor Show Color Dialog Box
ShowFont Show Font Dialog Box
ShowPrinter Show Print or Print Options Dialog Box
ShowHelp Invokes the Windows Help Engine


0
 
mlcktmguyAuthor Commented:
Yes, that worked better than the combo box approach.  I'm not sure why?
When I used the combo box I had 'stops' throughout the code to make sure that it was setting the printer properly based on what was selected.  It was, but when I printed the report it still went to the default printer.  I decided to try the common dialog box and it worked.  I still can't get the thing to print in landscape but I'll be posting another question on that.

Thanks for your help
0
 
Mikal613Commented:
I have the answer 2 that too when your ready
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.

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