# Creating Print Button for single record in Access Form



## surfmom (Jul 14, 2004)

I need to create a button that will print a report for the data just entered into an Access Form. I was successfully able to create a button which will print the report but it prints it for all records. I just need it to print the record which was just entered. Each record does receive a unique identifier (key field). Thanks for any help..I feel like I'm just beating my head against the wall at this point.


----------



## ransford (Mar 17, 2001)

Change name of Rpt_Customer to suit our report name

Put code behind your command button,


```
[SIZE=2]Dim stLinkCriteria as String


StrCriterion = "[unique identifier]=" & Me![unique identifier]


DoCmd.OpenReport "Rpt_Customer", acNormal, , stLinkCriteria[/SIZE]
```
If link fields are text then use this:

stLinkCriteria = "[unique identifier]=" & "'" & Me![unique identifier] & "'"


----------



## surfmom (Jul 14, 2004)

I'm a neophyte at this so bear with me. It appears that I need to enter a specific unique identifier into the code

"[unique identifier]=" & Me![unique identifier]

I need the system to automatically apply the ID (autonumber key field) for the record just entered as the selection criteria for the report. Is that possible?


----------



## ransford (Mar 17, 2001)

In your table do you have an autonumber?

If you do then this number should be used.

Lets say it is called CustomerID, you should have this control on your form and in your report.

When you have done that change [unique identifier] to {CustomerID].

You said in your original post:



> Each record does receive a unique identifier (key field).


Therefore I assumed that you already had an autonumber field.

You do not have to have an Autonumber filed but it is the easy way if you are just starting.

If you still don't get it to work , then post me a copy of your database (remove all data if you wish) and I will fix it for you.

I also have a sample db that covers this but it may be too confusing for you, but let me know and we will fix it one way or the other.


----------



## surfmom (Jul 14, 2004)

John,

Thanks so much for your help so far. I modified the code per your last post but the report still prints for all records. If you could take a look at my database I would be most appreciative. The form I am working with is Sales. The report I want to print is Buyer Sales Draft.


----------



## ransford (Mar 17, 2001)

Here is your db back and working.

Also the code in one of my posts was wrong;


```
Dim stLinkCriteria as String


StrCriterion = "[unique identifier]=" & Me![unique identifier]


DoCmd.OpenReport "Rpt_Customer", acNormal, , stLinkCriteria
```
should have read:


```
Dim StrCriterion as String


StrCriterion = "[unique identifier]=" & Me![unique identifier]


DoCmd.OpenReport "Rpt_Customer", acNormal, , StrCriterion
```
If my may give you a couple of pointers;
Give your ID's real meaning names e.g salesID productID modelID etc 
Never use # @ %V ^ etc in your field names.Never have spaces in your field names nor in the names of forms reports etc. Tables: tblSales Forms: frmSales Reports: rptSales SubForms: sfrmParts Combo boxes: cboModels.

Last rave before I post, you would make it much easier if you used cascading combo boxes for you make and model e.g when you select Buick and then Models you only see "Buick" models. Let me know if you want to know how and I will send you a db for filling the answers and I will fix it for you.


----------



## surfmom (Jul 14, 2004)

John,

Your help has been invaluable..now my challenge is to truly understand the command so I can modify and duplicate for other uses. If you don't mind I have one more question. I need to create two records from each sales record that is entered. As each single transaction results in two invoices (one for the seller and one for the buyer) I need to create a table with one record for each side of the transaction for Accounts Receivable statements. I am hoping that as a sale is entered in the Sales table a single record containing the saleID (I took your advice and made the field name more meaningful) and seller or buyer is created in a separate table. Is this possible? I've tried every possible query configuration and still have a single record which contains both the seller and buyer.

Thanks again for all your help

Kathryn


----------

