tols12
asked on
How do I print one record in a MS Access 2007 form?
In MS Access 2007, I have a table setup with all of my contacts. I then created a form where i can select in individual contact and see all of their information. I am wanting to somehow print the information for the contact i choose on my form. I tried adding a print button, but it prints every single record in my table. I want it to print ONLY the contact i have selected on the form. Does that make sense? So, if i have 100 contacts in my contact table. I go to my form and select a contact John Doe. The contact information for John Doe is now showing on my form. I would like to print only John Doe's information as i am seeing it on the form. How can i best accomplish this? Thanks!!!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! So i put the "DoCmd.PrintOut acSelection" in and it prints. Now i just need to format the form so it prints on one page. right now it prints 4 pages. About a 1/2 inch of my form is printing on another page. How do i adjust the page setup for printing?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So i saved it as a report. Now how do i create the link between my form and the report? Which coding are you referring to?
tols12,
did you look at the link i posted above ?
did you look at the link i posted above ?
Assuming that you have a field (ID) on your form which uniquely identifies that record, and the associated textbox control (txt_ID), and that the same field/controls exists in the report (which it will if you just did a SaveAs report). Then the code behind your Print button would look like:
Private Sub cmd_Print_Click
Docmd.openreport "reportname", acViewPreview, , "ID = " & me.txt_ID
End Sub
This would open the report in preview mode. If you want to simply print it, just delete the acViewPreview value or replace it with acViewNormal.
Private Sub cmd_Print_Click
Docmd.openreport "reportname", acViewPreview, , "ID = " & me.txt_ID
End Sub
This would open the report in preview mode. If you want to simply print it, just delete the acViewPreview value or replace it with acViewNormal.
ASKER
I did. This is what i pasted in the coding. The last line starting with "DoCmd" is highlighted in yellow. I get an error.
Private Sub cmdPrintRecord_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "Contact"
strCriteria = "[ID]='" & Me![ID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End Sub
I named the report "Contact".
Private Sub cmdPrintRecord_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "Contact"
strCriteria = "[ID]='" & Me![ID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End Sub
I named the report "Contact".
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fyed, that worked. Now i will just adjust the report to fit. Thank you!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!
is the name of the field for the record Identification ID ?
is the field a Number or Text Data type ?
is the field a Number or Text Data type ?
ASKER
Thank you for helping and being patient with me! I appreciate all of your help!!!!!
...see how much easier printing is when using reports...?
;-)
;-)
ASKER
It is a ton easier. :) I have learned something today! Thanks again for all of your help!!!
use the currently displayed record id in the form to filter the report