How to change the default printer 
Author Message
 How to change the default printer

Hi,

I'm trying to change the default printer from within my program, so I can
print a datareport created with VB6.

Does anyone know a way of doing this, using the windows API?

Using just VB doesn't work with the VB6 Data report:

Set printer = printers(1)

Thanks,

Toine van Deursen
Applidata b.v.
The Netherlands



Fri, 29 Aug 2003 23:30:15 GMT  
 How to change the default printer
Hi Toine
Try

Private sub selectDefaultPrinter()
Dim defPrinter As Printer
For Each defPrinter in Printers
If defprinter.DeviceName =" HP DESK C690" or whatever
Set Printer= defPrinter
Exit For
End if
Next
End Sub

Instead of DeviceName, you can use

defPrinter.Port ="LPT1" or whatever
or
defPrinter.DriverName ="HPDSKJTP" or whatever

Sukesh



Quote:
> Hi,

> I'm trying to change the default printer from within my program, so I can
> print a datareport created with VB6.

> Does anyone know a way of doing this, using the windows API?

> Using just VB doesn't work with the VB6 Data report:

> Set printer = printers(1)

> Thanks,

> Toine van Deursen
> Applidata b.v.
> The Netherlands



Fri, 29 Aug 2003 23:51:39 GMT  
 How to change the default printer
Thanks,

but that's the same as the statement:
Set printer = printers(1)

and like I said, that doesn't work.

Maybe someone else has an answer?

Yours sincerely,

Toine van Deursen
Applidata B.V.
The Netherlands


Quote:
> Hi Toine
> Try

> Private sub selectDefaultPrinter()
> Dim defPrinter As Printer
> For Each defPrinter in Printers
> If defprinter.DeviceName =" HP DESK C690" or whatever
> Set Printer= defPrinter
> Exit For
> End if
> Next
> End Sub

> Instead of DeviceName, you can use

> defPrinter.Port ="LPT1" or whatever
> or
> defPrinter.DriverName ="HPDSKJTP" or whatever

> Sukesh



> > Hi,

> > I'm trying to change the default printer from within my program, so I
can
> > print a datareport created with VB6.

> > Does anyone know a way of doing this, using the windows API?

> > Using just VB doesn't work with the VB6 Data report:

> > Set printer = printers(1)

> > Thanks,

> > Toine van Deursen
> > Applidata b.v.
> > The Netherlands



Fri, 29 Aug 2003 23:56:24 GMT  
 How to change the default printer
make sure that Printer.TrackDefault = True

Moshe.
Erez Business Softwares Ltd.



Quote:
> Hi,

> I'm trying to change the default printer from within my program, so I can
> print a datareport created with VB6.

> Does anyone know a way of doing this, using the windows API?

> Using just VB doesn't work with the VB6 Data report:

> Set printer = printers(1)

> Thanks,

> Toine van Deursen
> Applidata b.v.
> The Netherlands



Sat, 30 Aug 2003 00:37:01 GMT  
 How to change the default printer
Thanks,

But that doesn't work either?!?

I don't know what to do. When I select a printer using the commondialogbox
it does work. But I want to choose the printer using my own interface.

Does anyone else have a sugestion?

Thanks,

Toine van Deursen
Applidata b.v.
The Netherlands



Quote:
> make sure that Printer.TrackDefault = True

> Moshe.
> Erez Business Softwares Ltd.



> > Hi,

> > I'm trying to change the default printer from within my program, so I
can
> > print a datareport created with VB6.

> > Does anyone know a way of doing this, using the windows API?

> > Using just VB doesn't work with the VB6 Data report:

> > Set printer = printers(1)

> > Thanks,

> > Toine van Deursen
> > Applidata b.v.
> > The Netherlands



Sat, 30 Aug 2003 00:51:04 GMT  
 How to change the default printer
I have used this in the past.

Declare Function WriteProfileString Lib "kernel32" Alias
"WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As
String, ByVal lpszString As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long)
As Long
Public Const HWND_BROADCAST = &HFFFF
Public Const WM_WININICHANGE = &H1A

Function SetDefaultPrinter(ByVal PrinterName As String) As Boolean
  Dim DeviceLine As String
  Dim DevName As String
  Dim Ptr As Printer
  For I = 0 To Printers.Count - 1
    DevName = UCase(Printers(I).DeviceName)
    If InStr(DevName, UCase(PrinterName)) > 0 Then
      Set Ptr = Printers(I)
      DeviceLine = Ptr.DeviceName & "," & Ptr.DriverName & "," & Ptr.Port
      Exit For
    End If
  Next
  If DeviceLine = "" Then
    SetDefaultPrinter = False: Exit Function
  End If
  Call WriteProfileString("windows", "Device", DeviceLine)
  Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, 0)
  SetDefaultPrinter = True
End Function

hope this helps

--Joshua Baker



Quote:
> Hi,

> I'm trying to change the default printer from within my program, so I can
> print a datareport created with VB6.

> Does anyone know a way of doing this, using the windows API?

> Using just VB doesn't work with the VB6 Data report:

> Set printer = printers(1)

> Thanks,

> Toine van Deursen
> Applidata b.v.
> The Netherlands



Sat, 30 Aug 2003 01:21:35 GMT  
 How to change the default printer
Hello Toine

Just in case, maybe you must not be aware the printers count starts from 0
and not
1

The command

 Set  Printer = Printers(N)

works on my desktop.

N= 0, 1, 2 .........

Regards
Sukesh



Quote:
> Hi,

> I'm trying to change the default printer from within my program, so I can
> print a datareport created with VB6.

> Does anyone know a way of doing this, using the windows API?

> Using just VB doesn't work with the VB6 Data report:

> Set printer = printers(1)

> Thanks,

> Toine van Deursen
> Applidata b.v.
> The Netherlands



Sat, 30 Aug 2003 16:00:05 GMT  
 How to change the default printer
Joshua,

Thanks a lot. That does seem to work!!!!

Toine



Quote:
> I have used this in the past.

> Declare Function WriteProfileString Lib "kernel32" Alias
> "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As
> String, ByVal lpszString As String) As Long
> Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
> As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As
Long)
> As Long
> Public Const HWND_BROADCAST = &HFFFF
> Public Const WM_WININICHANGE = &H1A

> Function SetDefaultPrinter(ByVal PrinterName As String) As Boolean
>   Dim DeviceLine As String
>   Dim DevName As String
>   Dim Ptr As Printer
>   For I = 0 To Printers.Count - 1
>     DevName = UCase(Printers(I).DeviceName)
>     If InStr(DevName, UCase(PrinterName)) > 0 Then
>       Set Ptr = Printers(I)
>       DeviceLine = Ptr.DeviceName & "," & Ptr.DriverName & "," & Ptr.Port
>       Exit For
>     End If
>   Next
>   If DeviceLine = "" Then
>     SetDefaultPrinter = False: Exit Function
>   End If
>   Call WriteProfileString("windows", "Device", DeviceLine)
>   Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, 0)
>   SetDefaultPrinter = True
> End Function

> hope this helps

> --Joshua Baker



> > Hi,

> > I'm trying to change the default printer from within my program, so I
can
> > print a datareport created with VB6.

> > Does anyone know a way of doing this, using the windows API?

> > Using just VB doesn't work with the VB6 Data report:

> > Set printer = printers(1)

> > Thanks,

> > Toine van Deursen
> > Applidata b.v.
> > The Netherlands



Sat, 30 Aug 2003 16:47:44 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. How to change the default printer in an accessmodule

2. Can not change the default printer

3. ActivePrinter= Changes Win95 Default Printer

4. HELP: How to change the default printer in VB6

5. API Calls to Change the Default Printer

6. VB 3.0 -> change the default printer

7. Q: Changing the default printer

8. How to change the default printer

9. How to change the default printer?

10. How do I change the Default Printer from VB

11. How to change the default printer

12. 32 bit VB4 Changing Win95 Default Printer

 

 
Powered by phpBB® Forum Software