Avatar of inversojvo
inversojvo
Flag for Germany asked on

Erro 429: ActiveX control cannot create object

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
Microsoft AccessVisual Basic ClassicWeb Components

Avatar of undefined
Last Comment
inversojvo

8/22/2022 - Mon
peter57r

There's nothing wrong with that statement. It would stand on its own outside of all the other code in any case and still work.
You can just run it in the debug window and see if it gives a problem there.  
peter57r

I mean  like:
?Trim$(Left$(ActivePrinter, InStr(ActivePrinter, " on ")))
Muhammad Khan

have you used ON Error Resume Next in any of the place? in any level of function call stack?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
stevbe

This would not work if the PC does not have any printer set as the default printer.
ASKER CERTIFIED SOLUTION
inversojvo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.