Question : VBA - changed printer settings not always right executed

Hi,

I change the printer settings in an access-application. The created documents should be printed on another printer than the user´s current/default printer.

I work from time to time. From time to time not: I mean the document is printed on the  user´s default printer. It seems it depends also on the printer choosen by the access application.

Could anybody check my code (see enclosure) and explain me what´s wrong?

Would it be possbile that the wrong code causes defect to the printer drivers on the user´s pc?

Many thanks in advance and have a nice day!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
Public Sub setDruckerSchacht() 
  
    Const strMethSignatur As String = MODULE_NAME & "setDruckerSchacht" 
    
    On Error GoTo METH_ERR 
    
    Dim arrBuffer() As Long 
    Dim lngLaenge As Long 
    Dim lngRueck As Long 
    Dim udtDevMode As DEVMODE 
    Dim udtPrintDef As PRINTER_DEFAULTS 
    Dim lngRet As Long 
    Dim lngPtrDevMode As Long 
    Dim lngPrinter As Long 
    Dim strPrinter As String 
    
    'ifi: Druckernamen 
    strPrinter = gobjDrucker.Drucker 
    
    'ifi: Printer-Defaults-Struktur initialisieren 
    udtPrintDef.pDatatype = 0 
    udtPrintDef.pDevMode = 0 
    udtPrintDef.DesiredAccess = PRINTER_ALL_ACCESS 
    
    'ifi: Printer öffnen 
    lngRet = OpenPrinter(strPrinter, lngPrinter, udtPrintDef) 
    
    'ifi: Pufferlänge ermitteln 
    lngRet = GetPrinter(lngPrinter, 2, ByVal 0&, 0, lngLaenge) 
    
    'ifi: Puffer anpassen 
    ReDim arrBuffer((lngLaenge \ 4)) 
    
    'ifi: Printerinfos ermitteln (Level 2) 
    lngRet = GetPrinter(lngPrinter, 2, arrBuffer(0), lngLaenge, lngLaenge) 
  
    'ifi: Pointer auf die Devmode-Struktur 
    lngPtrDevMode = arrBuffer(7) 
    
    'ifi: Eigene Devmode-Struktur füllen 
    CopyMemory udtDevMode, ByVal lngPtrDevMode, Len(udtDevMode) 
    
    'ifi: Jetzt Schacht auswählen (1. Blatt = erstBlatt, Trennblatt = Trennblatt) 
    udtDevMode.dmDefaultSource = gobjDrucker.erstBlattID 
      
    'ifi: Änderungen zurück an die ursprüngliche Speicherstelle 
    CopyMemory ByVal lngPtrDevMode, udtDevMode, Len(udtDevMode) 
    
    'ifi: Jira #08010LW-87: Druckereinstellungen ändern 
    lngRet = DocumentProperties(0, lngPrinter, strPrinter, udtDevMode, udtDevMode, DM_IN_BUFFER) 
    
    lngRet = setPrinter(lngPrinter, 2, arrBuffer(0), 0) 
    
    'ifi: Anwendungen über die Änderungen informieren 
    lngRet = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, strPrinter) 
    
    'ifi: Drucker schließen 
    lngRet = ClosePrinter(lngPrinter) 
    

METH_EXIT: 
    Exit Sub 
    
METH_ERR: 
    MsgBoxMitErl strMethSignatur 
    Resume METH_EXIT 
    Resume 

End Sub

Answer : VBA - changed printer settings not always right executed

There certainly is:

Get-Mailbox | ForEach {Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity} | ft Identity, Devicetype, DeviceUserAgent, LastSuccessSync

Random Solutions  
 
programming4us programming4us