Hi,
I use Access 2000 (Windows XP) with Microsoft ActiveX Data Objects Recordset 2.8 and try to get printer properties (default printer) with the following code:
-----------
Public Sub getUserDefaultPrinter()
Dim hPrinter As Long
Dim pd As PRINTER_DEFAULTS
Dim dm As DEVMODE
Dim sPrinterName As String
Dim yDevModeData() As Byte
Dim iRet As Long
Dim Orientation As Long
Dim PaperSize As Long
Dim PaperLength As Long
Dim DefaultSource As Long
Dim PrintQuality As Long
On Error GoTo getUserDefaultPrinter_Error
'get the name of the current printer
sPrinterName = Trim$(Left$(ActivePrinter, InStr(ActivePrinter, " on ")))
pd.DesiredAccess = PRINTER_ALL_ACCESS
'Get the printer handle
iRet = OpenPrinter(sPrinterName, hPrinter, pd)
If (iRet = 0) Or (hPrinter = 0) Then
'Couldn't access the printer
Exit Sub
End If
'Find out how many bytes needed for the printer properties
iRet = DocumentProperties(0, hPrinter, sPrinterName, dm, dm, DM_IN_BUFFER)
'Make sure the byte array is large enough, including the
'100 bytes extra in case the printer driver is lying.
ReDim yDevModeData(0 To iRet + 100) As Byte
'Load the printer properties into the byte array
iRet = DocumentProperties(0, hPrinter, sPrinterName, dm, dm, DM_IN_BUFFER)
'Copy the byte array to the DEVMODE structure
Call CopyMemory(dm, yDevModeData(0), Len(dm))
'ifi: Globales Objekt initialisieren
If IsNull(gobjUserDefaultPrinter) Or gobjUserDefaultPrinter Is Nothing Then
Set gobjUserDefaultPrinter = New clsStandardDrucker
End If
'Get the value of the requested property
gobjUserDefaultPrinter.Name = sPrinterName
gobjUserDefaultPrinter.DefaultSource = dm.dmDefaultSource
On Error GoTo 0
Exit Sub
----------------------
and get the following error because of the line "sPrinterName = Trim$(Left$(ActivePrinter, InStr(ActivePrinter, " on ")))":
Error 429: ActiveX control cannot create object.
I really do not know why. It worked already and I have not change anything.
Many thanks for your help!
Have a nice day!
IsaF
You can just run it in the debug window and see if it gives a problem there.