Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2005, 04:01 PM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chacquard
Default view/print report from 2 different forms

Hi,

I have a report that I need to view or print from two different forms. the report is based on a query and is generated according to a selection made on the form. Specifically:

in the form "ReportMenu", we select an event ("ParmResume" field) and click on the command button to view or print the report.
In the query, the IdEvent field has to be = to the [Forms]![ReportMenu]![parmResume]

Now... in the "HistoricTransfer" form, I need to do the same, but now the IdEvent field has to be = to the [Forms]![HistoricTransfer]![parmResume] field...

How can I change my query to make it work from either form without creating a new query/report for each form...

Thank you

Chantal

 
Old January 5th, 2005, 04:40 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Use a button.

On the button On Click Event put this sort of code:

'====================Code Starts===
Dim stDocName As String
Dim stParameter As String
Dim stLinkCriteria As String

stDocName = "rptYourReportName"
stParameter = Forms![HistoricTransfer]![parmResume]

stLinkCriteria = "[QueryField] = " & "'" & stParameter & "'"

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
'====================Code Ends===

Actually, you should have one generic query with no paramters, and one generic report based on that query. Then use buttons to pass paramters to the report - and thus to the query.

I have a database with more than 300 reports, all based on two queries and two reports, but different parameters are passed on each button. I also use Combo boxes to select criteria. When using Combo Boxes to pass criteria, make sure the proper column is bound for the parameter being passed.

I hope this helps.


mmcdonal
 
Old January 5th, 2005, 04:42 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can also do this:

stParameter1
stParameter2

stParameter1 = ...
stParameter2 = ...

stLinkCriteria = "[QueryFieldOne] = " & "'" & stParameter1 & "'" & " AND [QueryFieldTwo] = " & "'" & stParameter2 & "'"

You can do this for many criteria as long as your query doesn't get confused.

mmcdonal
 
Old January 5th, 2005, 10:00 PM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chacquard
Default

Thank you very much... it works like a charm !!! :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
Print 2 Forms using 1 Button matto336 Access VBA 4 September 26th, 2007 07:36 AM
How to print from windows forms?? tycotrix C# 1 January 11th, 2007 09:45 AM
Print Forms on Saperate Pages itHighway HTML Code Clinic 1 November 21st, 2005 08:04 AM
Login fail Err when view report on Report Server dillig BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 22nd, 2004 05:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.