VCS_Report.bas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. Attribute VB_Name = "VCS_Report"
  2. Option Compare Database
  3. Option Private Module
  4. Option Explicit
  5. ' --------------------------------
  6. ' Structures
  7. ' --------------------------------
  8. Private Type str_DEVMODE
  9. RGB As String * 94
  10. End Type
  11. Private Type type_DEVMODE
  12. strDeviceName(31) As Byte 'vba strings are encoded in unicode (16 bit) not ascii
  13. intSpecVersion As Integer
  14. intDriverVersion As Integer
  15. intSize As Integer
  16. intDriverExtra As Integer
  17. lngFields As Long
  18. intOrientation As Integer
  19. intPaperSize As Integer
  20. intPaperLength As Integer
  21. intPaperWidth As Integer
  22. intScale As Integer
  23. intCopies As Integer
  24. intDefaultSource As Integer
  25. intPrintQuality As Integer
  26. intColor As Integer
  27. intDuplex As Integer
  28. intResolution As Integer
  29. intTTOption As Integer
  30. intCollate As Integer
  31. strFormName(31) As Byte
  32. lngPad As Long
  33. lngBits As Long
  34. lngPW As Long
  35. lngPH As Long
  36. lngDFI As Long
  37. lngDFr As Long
  38. End Type
  39. 'Exports print vars for reports
  40. Public Sub ExportPrintVars(ByVal obj_name As String, ByVal filePath As String)
  41. DoEvents
  42. Dim FSO As Object
  43. Set FSO = CreateObject("Scripting.FileSystemObject")
  44. Dim DevModeString As str_DEVMODE
  45. Dim DevModeExtra As String
  46. Dim DM As type_DEVMODE
  47. Dim rpt As Report
  48. 'report must be open to access Report object
  49. 'report must be opened in design view to save changes to the print vars
  50. DoCmd.OpenReport obj_name, acViewDesign
  51. Set rpt = Reports(obj_name)
  52. 'read print vars into struct
  53. If Not IsNull(rpt.PrtDevMode) Then
  54. DevModeExtra = rpt.PrtDevMode
  55. DevModeString.RGB = DevModeExtra
  56. LSet DM = DevModeString
  57. Else
  58. Set rpt = Nothing
  59. DoCmd.Close acReport, obj_name, acSaveNo
  60. Debug.Print "Warning: PrtDevMode is null"
  61. Exit Sub
  62. End If
  63. Dim OutFile As Object
  64. Set OutFile = FSO.CreateTextFile(filePath, overwrite:=True, Unicode:=False)
  65. 'print out print var values
  66. OutFile.WriteLine DM.intOrientation
  67. OutFile.WriteLine DM.intPaperSize
  68. OutFile.WriteLine DM.intPaperLength
  69. OutFile.WriteLine DM.intPaperWidth
  70. OutFile.WriteLine DM.intScale
  71. OutFile.Close
  72. Set rpt = Nothing
  73. DoCmd.Close acReport, obj_name, acSaveYes
  74. End Sub
  75. Public Sub ImportPrintVars(ByVal obj_name As String, ByVal filePath As String)
  76. Dim FSO As Object
  77. Set FSO = CreateObject("Scripting.FileSystemObject")
  78. Dim DevModeString As str_DEVMODE
  79. Dim DevModeExtra As String
  80. Dim DM As type_DEVMODE
  81. Dim rpt As Report
  82. 'report must be open to access Report object
  83. 'report must be opened in design view to save changes to the print vars
  84. DoCmd.OpenReport obj_name, acViewDesign
  85. Set rpt = Reports(obj_name)
  86. 'read print vars into struct
  87. If Not IsNull(rpt.PrtDevMode) Then
  88. DevModeExtra = rpt.PrtDevMode
  89. DevModeString.RGB = DevModeExtra
  90. LSet DM = DevModeString
  91. Else
  92. Set rpt = Nothing
  93. DoCmd.Close acReport, obj_name, acSaveNo
  94. Debug.Print "Warning: PrtDevMode is null"
  95. Exit Sub
  96. End If
  97. Dim InFile As Object
  98. Set InFile = FSO.OpenTextFile(filePath, iomode:=ForReading, create:=False, Format:=TristateFalse)
  99. 'print out print var values
  100. DM.intOrientation = InFile.ReadLine
  101. DM.intPaperSize = InFile.ReadLine
  102. DM.intPaperLength = InFile.ReadLine
  103. DM.intPaperWidth = InFile.ReadLine
  104. DM.intScale = InFile.ReadLine
  105. InFile.Close
  106. 'write print vars back into report
  107. LSet DevModeString = DM
  108. Mid(DevModeExtra, 1, 94) = DevModeString.RGB
  109. rpt.PrtDevMode = DevModeExtra
  110. Set rpt = Nothing
  111. DoCmd.Close acReport, obj_name, acSaveYes
  112. End Sub