Solved

Need help with MS-Access Query

Posted on 2014-11-13
6
117 Views
Last Modified: 2014-11-13
Experts:

I need some help with designing a query.  

The attached (testing) database contains the following:
- Table1
- Query1
- frmLogin
- rptGeneric

Process upon opening the database:
1. Open form "frmLogin"
2. Select any value from the listbox (this will open 'rptGeneric')
3. Then, open query 'Query1'

Additional Information:
- Query1 displays the average value for the 3 fields (Table 1)
- The 4th field "FormListBoxValue" is an expression which displays the last selected value from "frmLogin"

Here's what I need help with:
- Use the expression value (e.g., "AVG_3_Digit") as a baseline for another SQL expression so that I can compute the AVG value of any of the 3 fields based on whatever was selected.

For example (pseudo code) for the 2nd expression.  For example, change SQL from/to:
From: "SELECT Avg(Table1.[2-DigitNumber]) AS AVG_2_Digit FROM Table1;"
To: "SELECT Avg(Table1.[Forms]![frmLogin]![ListBoxTest]) AS AVG_2_Digit FROM Table1;"


Question #1: The proposed (pseudo) code -- with the [Forms statement] -- does NOT work.  How can I utilize a selected value from a form as field input for a SQL query?

Question #2: Right now, the form's listbox values mimic the query expressions (e.g., "AVG_2_Digit").  In the actual database, I need to be more descriptive with options in the form's listbox.   For example, the listbox may include options such as "Run report with average of 2-digit numbers."  That said, how can I translate that listbox value to match up with the actual field name [2-DigitNumber] or [AVG_2_Digit]?

Well, first things first... if I can get help with question #1, that would be a great starting point.

Thank you,
EEH
TestingDatabase.zip
0
Comment
Question by:ExpExchHelp
  • 4
  • 2
6 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40440541
test this
see query2 and codes behind listbox update event
TestingDatabase.accdb
0
 

Author Comment

by:ExpExchHelp
ID: 40440549
Rey:

Thank you for your response... when attempting to save your attachment, I'm getting a bunch of weird characters filling up the zip.   Would you be so kind and repost it... maybe as a .zip file?

Thanks,
EEH
0
 

Author Comment

by:ExpExchHelp
ID: 40440556
... filling up the screen (I meant to say).

Looking forward to your proposed solution.   EEH
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40440574
0
 

Author Comment

by:ExpExchHelp
ID: 40440636
Rey:

Most excellent... thank you for your support on this.   I think this is a brilliant solution.

One quick follow-up question.... in the report, what is the purpose of the unbound field "Text4".   If removed, I get an error on the line "Me.Text4 = Split(TempVars!GenericField, "_")(1)".

Cheers,
EEH
0
 

Author Closing Comment

by:ExpExchHelp
ID: 40440637
Most excellent solution!!!!  ;)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now