Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 March 19th, 2008, 11:20 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a drop down list in a query

I have a database with numerous sub-units contained within an overhead unit. I need to review reports for each of the sub-units separately so I would like to create a drop-down list so a user can just highlight the sub-unit they wish to view and bring up the report. Can this be done? I can't seem to get a drop-down list to perform in a query and I need a query to run a report.....right??
Any help would be greatly appreciated.

 
Old March 19th, 2008, 11:48 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Create a combo box using the wizard, and have it take unique values from the table that has this parameter column. I'll assume the column name is SubUnit.

If your report is based on a query, then add this to the SubUnit column Criteria line in the query designer:

[Forms]![frmMySelectionForm].[cboSubUnitComboBox]

Then EVERY time you open the report, it will look for the combo box, take the selected value, and open the report with only those subunits.

If you want the report to run without criteria, then you can either create a copy of the report just for sub units and create a copy of the query just for sub units with this criteria and open that when someone wants the sub units, and open your current report when they want all the info.

Alternatively, on the button to open the report (same report as current) where the user selects criteria, then just do this:

Dim sUnit As String
Dim sLink As String
Dim sDoc As String

sDoc = "rptMyCurrentReport"

sUnit = Me.cboSubUnitComboBox

sLink = "[SubUnit] = '" & sUnit & "'"

DoCmd.Open Report sDoc, , , sLink

The sLink variable should be in the WHERE clause section of the DoCmd line. You may also want to check to validate a selection.

Did that help?

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old March 19th, 2008, 11:50 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I should also mention that if you use the combo box wizard to create the look up, and then use the button wizard to open the report, it will ask you if the report should use any parameter on the form, and you can select the combo box and Access will build all of this for you.

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old March 19th, 2008, 11:53 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a MILLION!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down list ashu_gupta75 Excel VBA 1 October 15th, 2007 05:52 PM
Drop Down List Code Query rsm42 ASP.NET 1.0 and 1.1 Basics 1 July 4th, 2007 02:22 PM
Access: Drop down list in query newtoaccess Access 1 February 28th, 2006 08:30 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM





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