I tried to read the Report.PrtDevMode property using the appropriate structures. If I do a Unicode conversion on the string I get closer, but the values still don't seem correct.
I expect to see intOrientation = 2 and strDeviceName = "C552 Color" and a paper size of 11x17.
I am testing on Windows 10 and Server 2008 with Microsoft Access 2010 (32-bit)
What I have Tried
A simplified copy and paste from the help file:
Private Type str_DEVMODE
RGB As String * 94
End Type
Private Type type_DEVMODE
strDeviceName As String * 32
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
intDriverExtra As Integer
lngFields As Long
intOrientation As Integer
intPaperSize As Integer
intPaperLength As Integer
intPaperWidth As Integer
intScale As Integer
intCopies As Integer
intDefaultSource As Integer
intPrintQuality As Integer
intColor As Integer
intDuplex As Integer
intResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName As String * 32
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type
Public Sub CheckCustomPage()
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
Dim intResponse As Integer
' Opens report in Design view.
DoCmd.OpenReport "rptNavigationPaneGroups", acDesign
Set rpt = Reports("rptNavigationPaneGroups")
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
' Gets current DEVMODE structure.
' (I added the StrConv function)
DevString.RGB = StrConv(strDevModeExtra, vbUnicode)
LSet DM = DevString
' List the device name.
If DM.strDeviceName <> rpt.Printer.DeviceName Then
Debug.Print "Found: '" & DM.strDeviceName & _
"' instead of '" & rpt.Printer.DeviceName & "'"
End If
End If
Set rpt = Nothing
End Sub
If I use the vbUnicode conversion, I get this output:
Found: 'C552 Color ”-é/ '
instead of 'C552 Color'
Without the conversion, the name is completely unreadable:
Found: '????? ?? A?A?????? ?'
instead of 'C552 Color
I reviewed numerous articles, documentation, and posts describing the usage of the .PrtDevMode property and associated structure.
I compared the structure type with examples in the help file, online documentation, and other sources, but I don't find any examples that involve Unicode conversion, which seems like it might be a piece of the puzzle.
I could use the .Printer object to retrieve many of these properties, but I understand that some settings like the Media Type are only available through the PrtDevMode structure (which is designed to mirror the Win32 SDK).
I could resort to using API calls to query the system printers, but this doesn't solve the problem of needing to write the structure back to the report print settings.
Using this structure would also help me to serialize this data in a readable format so that it can be stored in version control, and written back to the report after the database is rebuilt from source files (which is my ultimate goal).
Any non-null pointers in the right direction?
