Solved

MS Access 2010 - a button that will save a record and open a report for that record

Posted on 2014-04-17
2
1,580 Views
Last Modified: 2014-05-08
Good afternoon - I'm creating an Access database to generate cab vouchers. A user presses a button, and is brought to a blank form. Information is then entered. At the bottom of the form, I need a button that saves the record, then opens a report - this report is the cab voucher. Every time I press the button, I get every cab voucher in the database - not the one that has just been entered.

How do I get the report to only generate the one record I just entered?
0
Comment
Question by:anglandp
2 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40007344
you need to filter the report using the current record in the form.

something like this

docmd.openreport "reportName",,,"[CabID]=" & me.cabID

see this link  http://support.microsoft.com/kb/209560
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40007345
You initially have to save the current record.

Then you have to pass a value to the OpenReport method that tells it to only generate the report for the selected record.  If your form is based on a table that has an autonumber (ID) field, you would normally do something like:

Private Sub cmd_Save_and_Print

     dim strCriteria as string

    me.dirty = True      'this saves the current record

    strCriteria = "[ID] = " & me.txt_ID

    docmd.OpenReport "rptName", acViewPreview, , strcriteria

End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now