Printing a subform?

brixie11

Registered User.
Local time
Today, 01:07
Joined
Jan 29, 2010
Messages
19
I have a problem with printing a Subform. On main form I have some data and 5 subforms. I want to print 1 subform. I created a form with button to print and inserted it to a mainform. When I press the print button it tries to print all the data in the table. I tried to do this:

Code:
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

    Dim stDocName As String
    Dim MyForm As Form

    stDocName = "Form1"
    Set MyForm = Screen.ActiveForm
    DoCmd.SelectObject acForm, stDocName, True
    DoCmd.PrintOut
    DoCmd.SelectObject acForm, MyForm.Name, False

Exit_Command5_Click:
    Exit Sub

Err_Command5_Click:
    MsgBox Err.Description
    Resume Exit_Command5_Click
    
End Sub
I can't figure it out what is wrong.
 
On the main form, try setting the Cycle property on the Other tab to Current Record. It might also be an idea for you to create a report instead, and when using Docmd.OpenReport use the Filter and/or Where paramaters to filter it base on what is displaying on the form.
 
In the subform I have a photo as an attachment.
 
I want to print that photo when I press the button. I'm not sure if I can print photo as attachment just to click on the button?
 
Which is exactly what a report is for. You can run the report in hidden mode and call the print command.
 
Forms are generally used to display data on the screen if you want a hard copy of this data then a Report would be the usual way to achieve this.

As previously mentioned by vbaInet.
 

Users who are viewing this thread

Back
Top Bottom