A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

opens a report



 
 
Thread Tools Display Modes
  #1  
Old April 28th, 2010, 03:44 PM posted to microsoft.public.access
jwebster1979
external usenet poster
 
Posts: 35
Default opens a report

I have a form that is basically an invoice, I want a command button that
opens a report that will print only the invoice I am viewing. I have seen
this done before but have drawn a blank on how to accomplish this.
thanks
  #2  
Old April 28th, 2010, 03:58 PM posted to microsoft.public.access
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default opens a report

hi j,

On 28.04.2010 16:44, jwebster1979 wrote:
I have a form that is basically an invoice, I want a command button that
opens a report that will print only the invoice I am viewing. I have seen
this done before but have drawn a blank on how to accomplish this.

You normally use the WhereCondition parameter of the DoCmd.OpenReport
action:

Sub OpenReport(ReportName,
[View As AcView = acViewNormal],
[FilterName],
[WhereCondition],
[WindowMode As AcWindowMode = acWindowNormal],
[OpenArgs])
Member of Access.DoCmd

Depending on your field and primary key names, you have to adapt this:

DoCmd.OpenReport _
"yourReportName", , , "primaryKeyField = " & Me![primaryKeyField]

You must include the 'primaryKeyField' in the data sources of the form
and the report. The name must be without any table name prefix.


mfG
-- stefan --
  #3  
Old April 28th, 2010, 09:15 PM posted to microsoft.public.access
fredg
external usenet poster
 
Posts: 4,386
Default opens a report

On Wed, 28 Apr 2010 07:44:01 -0700, jwebster1979 wrote:

I have a form that is basically an invoice, I want a command button that
opens a report that will print only the invoice I am viewing. I have seen
this done before but have drawn a blank on how to accomplish this.
thanks


First create a report that displays all of the data you want to show.

Then¡K.

Your table should have a unique prime key field.
In my example it is named [RecordID].

On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview , , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

as the Where clause.

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.