Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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!!!!!
0
tols12
Asked:
tols12
  • 6
  • 4
  • 3
  • +1
4 Solutions
 
Rey Obrero (Capricorn1)Commented:
it will be better to use a report to Print information.
use the currently displayed record id in the form to filter the report

0
 
Rey Obrero (Capricorn1)Commented:
see this link

How to Print a Single Record from a Form in a Report
http://support.microsoft.com/?kbid=209560
0
 
Jeffrey CoachmanCommented:
I agree with capricon1 that you should use a report for printing.

However, you can print the current form record with code like this on the click event of a button on your form:

    DoCmd.PrintOut acSelection


JeffCoachman
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tols12Author Commented:
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?
0
 
Dale FyeCommented:
As mentioned above, don't reformat your form so that it prints the way you want to, convert it to a report.

Open the form in design view, Select SaveAs, give it a new name, and select Report as the way to save it in the dropdown.  Now you can make minor changes to the formatting to ensure your report will print on a single page (or maybe two), instead of 4.  
0
 
tols12Author Commented:
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?
0
 
Rey Obrero (Capricorn1)Commented:
tols12,

did you look at the link i posted above ?
0
 
Dale FyeCommented:
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.
0
 
tols12Author Commented:
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".
0
 
Dale FyeCommented:
Chances are that your ID field is numeric, not a string, so replace:

strCriteria = "[ID]='" & Me![ID] & "'"

with

strCriteria = "[ID]=" & Me![ID]
0
 
tols12Author Commented:
fyed, that worked. Now i will just adjust the report to fit. Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0
 
Rey Obrero (Capricorn1)Commented:
is the name of the field for the record Identification  ID ?
is the field a Number or Text Data type ?
0
 
tols12Author Commented:
Thank you for helping and being patient with me! I appreciate all of your help!!!!!
0
 
Jeffrey CoachmanCommented:
...see how much easier printing is when using reports...?

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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now