Link to home
Start Free TrialLog in
Avatar of tols12
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!!!!!
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

it will be better to use a report to Print information.
use the currently displayed record id in the form to filter the report

ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tols12
tols12

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tols12

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 ?
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.
Avatar of tols12

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".
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tols12

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 ?
Avatar of tols12

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...?

;-)
Avatar of tols12

ASKER

It is a ton easier. :) I have learned something today! Thanks again for all of your help!!!