VBA how to print a subForm/datasheet or export to a report to print?

jacjacjac

New member
Local time
Today, 12:28
Joined
Dec 3, 2012
Messages
6
Hello,

My problem is I have a mainForm with a combo box that acts as a filter for a subForm/datasheet, the results are from a

database, so depending on what what was selected, it will dynamically update the subForm/datasheet.

The issue I want is whatever the user selects (and results displayed) I wish to be able to 'print' out the results. The

SubForm/datasheet has four columns, ID, FirstName, LastName, DateOfBirth.

Now im unsure of the best way, i thought I might be able to create a button (on the mainForm) that just prints what is

displayed in the subForm/datasheet or do i export it to a report, what is the easiest way to print out the results?

With whatever method, what is the process and code? I have googled it for both methds, printing out the datasheet (doesn't

seem like i can) or printing a report, i can't seem to manage it with the dynamic contents of the subForm/datasheet.

Thanks in advance,

Jac
 
First off jacjacjac, welcome.

Ok, the first thing to understand is forms are used to input and display data, you should not print them. That is what reports are for. What you need to do is create a report in the same way you created the subform (same table and fields). Then put a command button on either the Main Form (probably best) or the subform. If you use the wizard to do this it will take you through the necessary steps. Essentially you should end up with some code on the command buttons OnClick event that will open the Report for the detail selected in your combobox. it should look something like;

DoCmd.OpenReport ReportName,acViewNormal,"KeyFieldName=" & Forms!MainForm.ComboboxName

get the report & command button created and post back if you need help with the exact code
 
i am trying the exact thing as jacjacjac - where i print a report from a main and subform but i'm not sure how the code works. do i put brackets around it or put is like you have it. I put it like this but it has errors.

Private Sub REPORT_Click()
DoCmd.OpenReport(rptSPECS_PRINT1,[View As AcView=acViewNormal],[keySPEC NUMBER="*"],[Forms!frmSPECS_DRAWINGS.cboSubForm])
End Sub


I have a main form that pulls up a spec from a combo box and then the subform that list all the drawings that that spec is in and then I need to be able to print the results along with the spec information from the main form.
 
you need to make a report for the subform then add a button in the form design view. chose the name of the report
this is a macro not vba
 
Thanks but the report opens all the information in subform and not what I picked from the combo box.
 
Thanks but the report opens all the information in subform and not what I picked from the combo box.

make a query from the subform that the report get the value from it. in the field put ="what you put in the combobox"
 
I'm sorry i am not sure which field you are talking about. I created the queary from the main and subform but i'm not sure what to do next. I know basic access but when it comes to coding and macros, i am lost. thanks
 
I've created a query and a report and a button to open the report. but not too sure how to get it to print what I chose from the main form. but i'm getting closer!
 
I've created a query and a report and a button to open the report. but not too sure how to get it to print what I chose from the main form. but i'm getting closer!

on each field you have a criteria put there
Code:
="your combobox name"
 

Users who are viewing this thread

Back
Top Bottom