Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #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:

WinXP Pro
MS Access 2002

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

SQL statement in query qrylatesthistory:

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!
Reply With Quote
  #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

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
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 10:38 PM.

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