Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912

    Unanswered: Programmatically orientate a report

    Good morning Accesseers

    Call me a thicky pants if your like but....

    Is it possible to programmatically orientate (landscape or portrait) a report in print preview? I can't figure out how and can find no mention via the normal routes (google, searching forums etc.). I seem to recall a reference on these revered pages to a paper that anything available in an MS application as a menu option is also available for automation - but my memory may, yet again, be failing me.

    I have tried the printer object (available via the report object) orientation property however this appears to only affect the print rather than preview view.

    Many thanks as ever guys
    Testimonial:
    pootle flump
    ur codings are working excelent.

  2. #2
    Join Date
    Mar 2005
    Posts
    261
    Hi,

    I think you'll have to open the report in design view, alter the orientation part of PrtDevMode, then save & close design view and open it in print preview. Bit of a mess, but should work (as long as it's not an MDE)...

    Code:
    Option Explicit
    
    Type str_DEVMODE
        RGB As String * 94
    End Type
    
    Type type_DEVMODE
        strDeviceName As String * 16
        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 * 16
        lngPad As Long
        lngBits As Long
        lngPW As Long
        lngPH As Long
        lngDFI As Long
        lngDFr As Long
    End Type
    
    Sub OpenReport(strName As String, _
                                intOrientation As Integer)
        
        Dim DevString As str_DEVMODE
        Dim DM As type_DEVMODE
        Dim strDevModeExtra As String
        Dim rpt As Report
        
        ' Opens report in Design view.
        DoCmd.OpenReport strName, acDesign
        
        Set rpt = Reports(strName)
        If Not IsNull(rpt.PrtDevMode) Then
            
            strDevModeExtra = rpt.PrtDevMode
            DevString.RGB = strDevModeExtra
            LSet DM = DevString
            
            DM.intOrientation = intOrientation
            
            LSet DevString = DM            ' Update property.
            Mid(strDevModeExtra, 1, 94) = DevString.RGB
            rpt.PrtDevMode = strDevModeExtra
            
            DoCmd.Close acReport, strName, acSaveYes
            
            'Now open the report in print preview...
            DoCmd.OpenReport strName, acViewPreview
            
        Else
            
            MsgBox "Error: Unable to update printer properties for this report."
            
        End If
        
    End Sub
    Then just call it like:
    Code:
    OpenReport "ReportName", 1
    for Portrait and
    Code:
    OpenReport "ReportName", 2
    for landscape.

    I can't think of another way of doing it...

    HTH

    Wayne Phillips
    http://www.everythingaccess.com
    Last edited by waynephillips; 12-18-05 at 06:01.

  3. #3
    Join Date
    Mar 2005
    Posts
    261
    Actually just found you can do it with SendKeys...

    Code:
    Sub OpenReportLandscape(strName As String)
    
        DoCmd.OpenReport strName, acViewPreview
        SendKeys "%FU{RIGHT}%L{ENTER}", True
    
    End Sub
    Problem is that the menu keys might be different on different versions of Access (haven't checked).

    HTH

    Wayne Phillips
    http://www.everythingaccess.com

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by waynephillips
    Bit of a mess, but should work (as long as it's not an MDE)...
    Ah - that is me stuck....

    until

    Quote Originally Posted by waynephillips
    Actually just found you can do it with SendKeys...
    Thanks very much as ever Wayne. I'll have a play with the sendkeys - putting aside my usual reticence to use sendkeys
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912

    Took a long time but...

    Cheers Wayne - works fine. It seems a report can't change it's own orientation (not sure why - couldn't be bothered trying to figure out) and since the report evaluates the required orientation I had to create a property and have the calling code set the orientation based on that.

    Next task is to see if the report can read it's current orientation and inhibit the sendkeys if it is already correct.

    Thanks again.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by pootle flump
    Next task is to see if the report can read it's current orientation and inhibit the sendkeys if it is already correct.
    Yes it can and yes it can
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Typical - model it in a dummy database and Robert is your mothers brother. Pop it in the real thing and nowt works.

    Report checks its current and required orientation. Sets a public property based on this. Calling proc immediately checks this the line after the Docmd.OpenReport... line. The Sendkeys line is getting executed but nothing happens. Cut down the Sendkeys to the minimum - still nothing. I'm not too used to using send keys so that might be unsticking me. The report does, however, take a long time to run which is making me think that the whole sendkeys thing might be a bad idea anyway once users start flicking around in windows. Any thoughts?

    Code:
      Private Sub HandleSpecialCases(CaseNotes As String)
    	
    	Dim rpt As Access.Report
    	Dim str As String
    	
    	If CaseNotes = "rptExStuRes" Then
    		
    		Set rpt = Reports(CaseNotes)
    		
    		str = rpt.ReportOrientation
    		
    		Set rpt = Nothing
    		
    		If str <> "N" And str <> "" Then
    			Debug.Print "sending Key: " & str
    			
    			'SendKeys "%FU{RIGHT}%" & str & "{ENTER}", True
    			SendKeys "%F", True
    			
    			Debug.Print "SendKeys '%F', True"
    			
    		End If
    	
    	End If
    End Sub
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Mar 2005
    Posts
    261
    Hmm... try setting the Wait parameter of SendKeys to False - perhaps Access is getting into a recursive loop... (complete guess...)

    EDIT: Sorry, I thought you meant that the report was taking longer with the SendKeys call.

  9. #9
    Join Date
    Mar 2005
    Posts
    261
    The report does, however, take a long time to run which is making me think that the whole sendkeys thing might be a bad idea anyway once users start flicking around in windows. Any thoughts?
    You can't programatically change the orientation of a preview-opened report through the Access object model. Therefore you only have the two options, as already discussed. i.e.

    1. Open in design view, change the orientation, save the report, open in preview.
    2. use SendKeys.

    I seem to remember you can't do #1 because you're in an MDE and therefore can't make changes to a report in design view.

    Therefore, sadly, #2 is your only option. I also hate SendKeys, and avoid it like the plague, but unless you wan't to just create two seperate reports, you're a bit stuck!

    Actually, I guess you could programatically duplicate the report during development so that you can, for example, have report A_Portrait and create A_Landscape programatically before making your MDE (or just create them manually if you're only dealing with a couple).
    Last edited by waynephillips; 01-12-06 at 10:19.

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by waynephillips
    Therefore, sadly, #2 is your only option. I also hate SendKeys, and avoid it like the plague, but unless you wan't to just create two seperate reports, you're a bit stuck!

    Actually, I guess you could programatically duplicate the report during development so that you can, for example, have report A_Portrait and create A_Landscape programatically before making your MDE (or just create them manually if you're only dealing with a couple).
    I think that is the inevitable path - one I have been trying to avoid as the report contains quite a bit of (shifting) business knowledge. Oh - for inheritance in Access!

    Ah well - time to bite the bullet I think. Thanks for your help
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •