Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old April 21st, 2009, 05:10 PM
Registered User
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Provide parameter to query for dynamic report

Please help.

How do I use selection from Combo box as query criteria? That is, how do I dynamically change report by changing criteria (e.g. Staff Name) after WHERE in query qrylatesthistory based on combo box cboStaff? Staff Name is one selection option for cboStaff.

I’ve been creating new queries and copying and pasting the following lines to reflect the correct query for the Filtername argument. It’s just a lot of maintenance when Staff Name is added or deleted.

Here’s the VBA Code I’ve used:

Dim stDocName As String

stDocName = "RptAdhereToPlan"
DoCmd.OpenReport stDocName, acPreview, Filtername:="qrylatesthistory"

Here’s my scenario:


Given:
WinXP Pro
MS Access 2002

cboStaff is a combo box for selecting different names; located on it own form.

SQL statement in query qrylatesthistory:

SELECT *
FROM qsellatest INNER JOIN QSelHistory ON qsellatest.MaxOfUpdateKey = QSelHistory.UpdateKey
WHERE (((QSelHistory.Resource) Like "StaffName") OR ((QSelHistory.UpdatedBy) Like "StaffName") AND ((QSelHistory.Complete)=No));

So I've been going in and changing "StaffName" to something else and saving query as another name. Then adding the new query to Filtername argument.

Any help is appreciated. Thanks in advance!
  #2 (permalink)  
Old April 22nd, 2009, 10:30 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Actually, I would not do it this way only because it seems like a lot of hoops to do something quite simple.

I would set up the query with the proper fields that I want to come out of it, including UpdatedBy, without any criteria. The make the query the record source for the report. If you open the report by itself, it would give you all the records. However, if you open the report via the form, the code would look like this.

DoCmd.OpenReport stDocName, acPreview, , "[UpdatedBy] = '" & Me.cboStaff & "'"
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter Query Help Normie Access 5 February 19th, 2008 01:50 PM
Dynamic Loading of Parameter List from a file erictelcoguy Crystal Reports 1 July 14th, 2005 10:13 AM
Dynamic sub-reports with parameter passing safecoder Crystal Reports 0 October 27th, 2004 12:26 PM
Non query Report Parameter qa BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 July 2nd, 2004 02:49 PM
Parameter Query Ben Access VBA 1 June 27th, 2003 12:13 PM





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