Solved Print a landscape form (1 Viewer)

zelarra821

Registered User.
Local time
Today, 01:19
Joined
Jan 14, 2019
Messages
809
Buenas tardes.

I am trying to print a form, and I have succeeded in this way:

Code:
Private Sub CdmImprimir_Click()
    On Error GoTo err_lbl
    
    Dim Titulo As String
    Dim Ruta As String
    
    Titulo = Screen.ActiveForm.Caption
    Ruta = BuscaCarpeta(Me)
    
    If Ruta = "" Then
        Exit Sub
    Else
    DoCmd.OutputTo acOutputForm, , acFormatPDF, Ruta & "\" & Titulo & ".pdf", 1
    End If
Salida:
    Exit Sub
err_lbl:
    MsgBox "CdmImprimir: " & Err.Number & " " & Err.Description, vbInformation, NombreBD
    Resume Salida
End Sub

However, I would like to change the orientation of the PDF, so that instead of portrait it comes out as landscape.

How can I get it?

I have the BuscaCarpeta function in a module, because I use it in more places, and basically what it does is return the path of the folder that the user has selected.

Thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:19
Joined
Oct 29, 2018
Messages
21,469
Normalmente, you would print a report and not a form. Is there any way you could create a report instead? Just curious...
 

zelarra821

Registered User.
Local time
Today, 01:19
Joined
Jan 14, 2019
Messages
809
I had already thought about it, but I have a graph that I change with checkboxes and combos as I am interested, and I do not know if that will be possible to do in a report. Look:

ScreenShot001.jpg
 

zelarra821

Registered User.
Local time
Today, 01:19
Joined
Jan 14, 2019
Messages
809
Well, it's easier than I thought. With this line before printing it is solved:

Code:
Forms (Me.Name) .Printer.Orientation = acPRORLandscape

That is, the first code that I have put would look like this:

Code:
Private Sub CdmImprimir_Click()
    On Error GoTo err_lbl

    Dim Titulo As String
    Dim Ruta As String

    Titulo = Screen.ActiveForm.Caption
    Ruta = BuscaCarpeta(Me)

    If Ruta = "" Then
        Exit Sub
    Else
    Forms(Me.Name).Printer.Orientation = acPRORLandscape
    DoCmd.OutputTo acOutputForm, , acFormatPDF, Ruta & "\" & Titulo & ".pdf", 1
    End If
Salida:
    Exit Sub
err_lbl:
    MsgBox "CdmImprimir: " & Err.Number & " " & Err.Description, vbInformation, NombreBD
    Resume Salida
End Sub

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:19
Joined
Oct 29, 2018
Messages
21,469
Well, it's easier than I thought. With this line before printing it is solved:

Code:
Forms (Me.Name) .Printer.Orientation = acPRORLandscape

That is, the first code that I have put would look like this:

Code:
Private Sub CdmImprimir_Click()
    On Error GoTo err_lbl

    Dim Titulo As String
    Dim Ruta As String

    Titulo = Screen.ActiveForm.Caption
    Ruta = BuscaCarpeta(Me)

    If Ruta = "" Then
        Exit Sub
    Else
    Forms(Me.Name).Printer.Orientation = acPRORLandscape
    DoCmd.OutputTo acOutputForm, , acFormatPDF, Ruta & "\" & Titulo & ".pdf", 1
    End If
Salida:
    Exit Sub
err_lbl:
    MsgBox "CdmImprimir: " & Err.Number & " " & Err.Description, vbInformation, NombreBD
    Resume Salida
End Sub

Thanks
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

isladogs

MVP / VIP
Local time
Today, 00:19
Joined
Jan 14, 2017
Messages
18,218
FWIW, the only time I ever needed to print a form (in landscape view), I used an autokeys macro to perform a screengrab using a keyboard shortcut Shift +F3, then printed the resulting image.
It worked...but using a report is much better! And yes, you can replicate your form chart items easily in a report
 

zelarra821

Registered User.
Local time
Today, 01:19
Joined
Jan 14, 2019
Messages
809
Ok, thank you very much, I'll test what you say.
 

Users who are viewing this thread

Top Bottom