Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting default page orientation on Access application.

Status
Not open for further replies.

djmc

Programmer
Jun 12, 2002
179
CA
How do I set the default page orientation for the Access application everytime it loads up. (i.e Landscape or Portriat) I already have a function in my modules which is set to load during startup of the application.
 
You can set Windows' default orientation using very low-level API calls, however, Access stores unique DevMode information for each form and report.

Typically, runtime printing changes in Access refer to a specific report's properties, for example:
Code:
  Dim devmode As udtDEV_MODE
  Dim strDM As String
  Dim rpt As Report
  
  DoCmd.OpenReport "MyReport", acViewDesign
  Set rpt = Reports("MyReport")
  strDM = rpt.PrtDevMode


To set the orientation for a report (or other PrtDevMode properties) you must be using full Access too since you need to enter design mode for the report. Here's a short example:

Code:
Type str_DEVMODE
    RGB As String * 94
End Type

Type DevMode
  dmDeviceName As String * 16
  dmSpecVersion As Integer
  dmDriverVersion As Integer
  dmSize As Integer
  dmDriverExtra As Integer
  dmFields As Long
  dmOrientation As Integer
  dmPaperSize As Integer
  dmPaperLength As Integer
  dmPaperWidth As Integer
  dmScale As Integer
  dmCopies As Integer
  dmDefaultSource As Integer
  dmPrintQuality As Integer
  dmColor As Integer
  dmDuplex As Integer
  dmYResolution As Integer
  dmTTOption As Integer
  dmCollate As Integer
  dmFormName As String * 16
  dmUnusedPadding As Integer
  dmBitsPerPel As Integer
  dmPelsWidth As Long
  dmPelsHeight As Long
  dmDisplayFlags As Long
  dmDisplayFrequency As Long
End Type

Public Function SetPrinterOrientation(ByVal strReportName As String, _
            ByVal enumDirection As PrinterOrientationConstants) As Boolean
On Error GoTo ErrHandler
  
  Dim dm As DevMode
  Dim strDevModeString As str_DEVMODE
  Dim strTemp As String
  Dim strMsg As String
  Dim rpt As Report
  
  'this triggers an error when arg references invalid report
  strTemp = CurrentProject.AllReports(strReportName).Name
   
  'open in design view
  DoCmd.OpenReport strReportName, acViewDesign
  Set rpt = Reports(strReportName)
  
  'set type info
  strDevModeString.RGB = rpt.PrtDevMode
  LSet dm = strDevModeString
  
  'captured DevMode, change orientation
  dm.dmOrientation = enumDirection
  LSet strDevModeString = dm
  
  'assign and save changes to report
  rpt.PrtDevMode = strDevModeString.RGB
  DoCmd.Close acReport, strReportName, acSaveYes

  SetPrinterOrientation = True
  
ExitHere:
  Exit Function
ErrHandler:
  Select Case Err
    Case 2467
      strMsg = "Report: " & strReportName & " not found!"
    Case Else
      strMsg = "Error: " & Err & " - " & Err.Description
  End Select
  MsgBox strMsg, vbCritical, "SetPrinterOrientation Error"
  Resume ExitHere
End Function



VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top