chestera
asked on
Printer Selection from combo box
Hi
I have a annoying problem I have a form with a combo box that lists printers on a PC. in properties are the following
Data
Row Source Type FillPrinterList (Function call)
Format
Column Count = 4
ColumnWidth = ;0cm;0cm;0cm
pName = me!cboPrinter.Column(1)
Problem it works and other times I get Null Value in pName
with the pName = Me!cboPrinter.Column(1)
I have tried on exit, on focus etc
I must be doing something wrong. If some one can see the problem help would be most apprciated
chestera
I have a annoying problem I have a form with a combo box that lists printers on a PC. in properties are the following
Data
Row Source Type FillPrinterList (Function call)
Format
Column Count = 4
ColumnWidth = ;0cm;0cm;0cm
pName = me!cboPrinter.Column(1)
Problem it works and other times I get Null Value in pName
with the pName = Me!cboPrinter.Column(1)
I have tried on exit, on focus etc
I must be doing something wrong. If some one can see the problem help would be most apprciated
chestera
You specify 4 columns but you define the width for only 3.
If the first column is the name of the printer, then pName = me!cboPrinter.Column(1)
is incorrect.
It can be stated in either of two ways:
pName = me!cboPrinter.Column(0)
or
pName = me!cboPrinter
Comboboxes are zero-based numbering (satrts at zero) for reference but the boundccolumn property starts at 1 not zero.
I hope that this helps.
If the first column is the name of the printer, then pName = me!cboPrinter.Column(1)
is incorrect.
It can be stated in either of two ways:
pName = me!cboPrinter.Column(0)
or
pName = me!cboPrinter
Comboboxes are zero-based numbering (satrts at zero) for reference but the boundccolumn property starts at 1 not zero.
I hope that this helps.
"You specify 4 columns but you define the width for only 3"
The 4th column will be the defined by the Width of the combo box ... and the 4th column is probably a description of the printer.
Also, sounds like the printer name is in physical column 2, thus Column(1) would be correct.
mx
The 4th column will be the defined by the Width of the combo box ... and the 4th column is probably a description of the printer.
Also, sounds like the printer name is in physical column 2, thus Column(1) would be correct.
mx
ASKER
databasemax
I have tried (0) and (1) it seems (1) it the right column but it's erratic Works then spits the dummy and doesn't work. The complet code is quite large. I will post the FillPrinterList portion.
chestera
I have tried (0) and (1) it seems (1) it the right column but it's erratic Works then spits the dummy and doesn't work. The complet code is quite large. I will post the FillPrinterList portion.
chestera
ASKER
databasemx
Here it the FillPrintList code
' Code from:
' Microsoft Access 95 How-To
' (c) 1998 Ken Getz and Paul Litwin
' All rights reserved.
' You may only use this code as part of an application
' that requires its use. You must including this
' notice intact. You may not distribute the code
' as your own work, nor can you distribute the
' code on its own.
Function ahtGetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean
' Retrieve the default printer information. Though
' the function dutifully returns True if the
' values were available, and False otherwise, Windows
' really isn't happy without a default printer, and
' this situation rarely comes up.
' In:
' dr: a aht_tagDeviceRec structure to fill in
' Out:
' Return Value: True if info available, False otherwise.
' dr: filled in with default printer information,
' if it was available (check the function's return
' value).
'
' Comments:
' Requires the ahtGetToken() function from basGetToken
' Requires the ahtGetINIString() function from basINIFile
' Requires type definitions from basPrintTypes
Dim strBuffer As String
strBuffer = ahtGetINIString("Windows", "Device")
If Len(strBuffer) > 0 Then
With dr
.drDeviceName = ahtGetToken(strBuffer, ",", 1)
.drDriverName = ahtGetToken(strBuffer, ",", 2)
.drPort = ahtGetToken(strBuffer, ",", 3)
End With
ahtGetDefaultPrinter = True
Else
ahtGetDefaultPrinter = False
End If
End Function
Function ahtSetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean
' Set the default printer device in Win.INI
' In:
' dr: a aht_tagDeviceRec structure to use as
' the source of information.
' Out:
' Return Value: True if set correctly, False otherwise.
' If successful, writes a string in the form:
' device=HP LaserJet 4,HPPCL5E,LPT1:
' to your Win.INI file.
'
' Comments:
' Requires the aht_apiWriteProfileString( ) declaration from basINIFile
' Requires type definitions from basPrintTypes
Dim strBuffer As String
' Build up the appropriate string.
strBuffer = dr.drDeviceName & ","
strBuffer = strBuffer & dr.drDriverName & ","
strBuffer = strBuffer & dr.drPort
' Now write that string out to WIN.INI.
ahtSetDefaultPrinter = (aht_apiWriteProfileString ("Windows" , _
"Device", strBuffer) <> 0)
End Function
Private Sub TestDefaultPrinter()
' Test the ahtDefaultPrinter() function.
' Fill in a DeviceRec structure with
' the pieces of the default printer info,
' and then print them out.
Dim dr As aht_tagDeviceRec
If ahtGetDefaultPrinter(dr) Then
Debug.Print "Device: "; dr.drDeviceName
Debug.Print "Driver: "; dr.drDriverName
Debug.Print "Port : "; dr.drPort
End If
End Sub
Here it the FillPrintList code
' Code from:
' Microsoft Access 95 How-To
' (c) 1998 Ken Getz and Paul Litwin
' All rights reserved.
' You may only use this code as part of an application
' that requires its use. You must including this
' notice intact. You may not distribute the code
' as your own work, nor can you distribute the
' code on its own.
Function ahtGetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean
' Retrieve the default printer information. Though
' the function dutifully returns True if the
' values were available, and False otherwise, Windows
' really isn't happy without a default printer, and
' this situation rarely comes up.
' In:
' dr: a aht_tagDeviceRec structure to fill in
' Out:
' Return Value: True if info available, False otherwise.
' dr: filled in with default printer information,
' if it was available (check the function's return
' value).
'
' Comments:
' Requires the ahtGetToken() function from basGetToken
' Requires the ahtGetINIString() function from basINIFile
' Requires type definitions from basPrintTypes
Dim strBuffer As String
strBuffer = ahtGetINIString("Windows",
If Len(strBuffer) > 0 Then
With dr
.drDeviceName = ahtGetToken(strBuffer, ",", 1)
.drDriverName = ahtGetToken(strBuffer, ",", 2)
.drPort = ahtGetToken(strBuffer, ",", 3)
End With
ahtGetDefaultPrinter = True
Else
ahtGetDefaultPrinter = False
End If
End Function
Function ahtSetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean
' Set the default printer device in Win.INI
' In:
' dr: a aht_tagDeviceRec structure to use as
' the source of information.
' Out:
' Return Value: True if set correctly, False otherwise.
' If successful, writes a string in the form:
' device=HP LaserJet 4,HPPCL5E,LPT1:
' to your Win.INI file.
'
' Comments:
' Requires the aht_apiWriteProfileString(
' Requires type definitions from basPrintTypes
Dim strBuffer As String
' Build up the appropriate string.
strBuffer = dr.drDeviceName & ","
strBuffer = strBuffer & dr.drDriverName & ","
strBuffer = strBuffer & dr.drPort
' Now write that string out to WIN.INI.
ahtSetDefaultPrinter = (aht_apiWriteProfileString
"Device", strBuffer) <> 0)
End Function
Private Sub TestDefaultPrinter()
' Test the ahtDefaultPrinter() function.
' Fill in a DeviceRec structure with
' the pieces of the default printer info,
' and then print them out.
Dim dr As aht_tagDeviceRec
If ahtGetDefaultPrinter(dr) Then
Debug.Print "Device: "; dr.drDeviceName
Debug.Print "Driver: "; dr.drDriverName
Debug.Print "Port : "; dr.drPort
End If
End Sub
Albert Kallal provides a code module that helps with switching printers, and part of that code shows how to get a listing of the available printers:
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html
you can easily add the printers on a custom menu and it would take literally seconds to so.
Are you trying to add a way to select printers?
I will be away for the next two days, so I would hope that one of the experts could direct this person in the method to make a custom menubar from the GUI for the printer.
Good Luck !!
Are you trying to add a way to select printers?
I will be away for the next two days, so I would hope that one of the experts could direct this person in the method to make a custom menubar from the GUI for the printer.
Good Luck !!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually, I've never seen the need for the various code over the years for selecting printers. If you bring up any report in print preview, you can right click (or use the File menu) and you have available (built in) the Print ... and Page Setup menus. From these dialogs, the use can select any printer that is installed and set other properties for either the printer and/or the page. In addition, you can create your own right click menu with further added functionality.
I suppose the code might be necessary if ... you were not using print preview and needed to go directly to a specific printer. I alway use print preview ... before shooting a load of paper out to a printer blindly.
mx
I suppose the code might be necessary if ... you were not using print preview and needed to go directly to a specific printer. I alway use print preview ... before shooting a load of paper out to a printer blindly.
mx
ASKER
databasemx
Office 2003 no longer supports Print dialog box in mail merge sendto printer. I need to select printer Number of copies and tray so I designed a smiple dialog box
WordDoc.Application.Active Printer = pName
WordDoc.Application.PrintO ut Copies:=nCopies
With Options
.DefaultTray = "Tray" & nTray
End With
I have since found via lsmconsulting I don't need this massive code I am currently using.
chestera
Office 2003 no longer supports Print dialog box in mail merge sendto printer. I need to select printer Number of copies and tray so I designed a smiple dialog box
WordDoc.Application.Active
WordDoc.Application.PrintO
With Options
.DefaultTray = "Tray" & nTray
End With
I have since found via lsmconsulting I don't need this massive code I am currently using.
chestera
ASKER
lmsconsulting
I modified using your code now working 100%. problem with my code it wouldn't always populate variable pName from the combo box from time to time I would get invalid use of null. I think it might be how the combo box was set up. Anyway thanks for that code
chestera
I modified using your code now working 100%. problem with my code it wouldn't always populate variable pName from the combo box from time to time I would get invalid use of null. I think it might be how the combo box was set up. Anyway thanks for that code
chestera
Hi Gentlemen,
If you have a few minutes,
Just posted a related question here:
https://www.experts-exchange.com/questions/25135122/Access-2003-Excel-2003-looping-thru-the-printers-object.html
Would LSM's solution work for my situation?
If so your help would be appreciated, bec. i do not know how to use the code.
tx, sandra
If you have a few minutes,
Just posted a related question here:
https://www.experts-exchange.com/questions/25135122/Access-2003-Excel-2003-looping-thru-the-printers-object.html
Would LSM's solution work for my situation?
If so your help would be appreciated, bec. i do not know how to use the code.
tx, sandra
Seems it would be an issue with the List fill function. Can you post the code for that?
mx