Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Blacktown, Sydney, New South Wales, Australia
    Posts
    175
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Landscape Orientation (AC97 SR-2)

    I am trying to create a button to print the current form record. The wizard created the following code.

    Private Sub btnPrintRecord_Click()
    On Error GoTo Err_btnPrintRecord_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.PrintOut acSelection

    Exit_btnPrintRecord_Click:
    Exit Sub

    Err_btnPrintRecord_Click:
    MsgBox Err.Description
    Resume Exit_btnPrintRecord_Click

    End Sub

    I wish to print the form in 'Landscape'. I have searched Help, and this forum, but am unable to find a VBA solution to Page Setup that allows orientation.

    Hope someone out there can help

    TIA

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Landscape Orientation (AC97 SR-2)

    You may not want to hear this, but I'd suggest that you create a report based on the same table or query as the form. Chances are, the layout of your form is not ideal for printing. You can optimize the report for the printer (including landscape orientation), while leaving the form optimized for on-screen editing.

    The code behind the button then looks like

    Private Sub btnPrintRecord_Click()
    On Error GoTo Err_btnPrintRecord_Click
    If Me.Dirty Then
    RunCommand acCmdSaveRecord
    End If
    DoCmd.OpenReport "rptMyReport", acViewPreview, , "[UniqueKey] = " & Me.[UniqueKey]
    Exit Sub
    Err_btnPrintRecord_Click:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    Replace rptMyReport by the name of the report, and UniqueKey by the name of a field that uniquely identifies the current record of the form.
    The check for Me.Dirty is meant to save the current record if it has been modified, so that the report will display the correct values.
    The check for Err <> 2501 is meant to avoid an error message if the opening of the report is canceled for some reason.

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Landscape Orientation (AC97 SR-2)

    When you open the form in Print Preview, you can use Page Setup dialog to set orientation to landscape. This setting is saved with the form. I'm not aware of any way to set this in VBA.

    By the way you may want to replace that archaic "DoMenuItem" wizard-generated code with:
    <pre> DoCmd.RunCommand acCmdSelectRecord
    DoCmd.PrintOut acSelection
    </pre>

    As noted by HansV reports are designed for printing, while forms are intended for screen display. You can create report based on form by selecting form in database window, right click then "Save As" report. You will still have to clean up the report format for optimal results, but this will save some time.

  4. #4
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Blacktown, Sydney, New South Wales, Australia
    Posts
    175
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Landscape Orientation (AC97 SR-2)

    Thanks to both replies. Will inform user his spec has been modified to take advantage of New Programming techniques and undocumented features.

Posting Permissions

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