Solved

Access 2010 Query Expression

Posted on 2015-01-14
18
64 Views
Last Modified: 2015-01-18
Hi Experts,
This shouldn't be a problem for me but it is.  I can't get the following to select properly.

The field is called [AGE_GROUP] and may contain the characters "A" or 'Y".

The Criteria row code is:
IIf([00_PARAMETER_DATA].[ALPHA_PARM_3]="B",Like "*",[00_PARAMETER_DATA].[ALPHA_PARM_3])

What should happen:
- If ALPHA_PARAMETER_3 = "B" then select all records.  i.e. Value "A" and "Y" records.
- If ALPHA_PARAMETER_3  = "A" then select only value "A" records.
- If ALPHA_PARAMETER_3 = "Y" then select only value "Y" records.

What should the syntax be?

Thanks.
Bob Collison.
0
Comment
Question by:Bob_Collison
  • 9
  • 7
18 Comments
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
It will probably look something like this
SELECT [AGE_GROUP], [ALPHA_PARM_3]
FROM mytable
WHERE IIf([ALPHA_PARM_3] In ("A","Y"),[AGE_GROUP]=[ALPHA_PARM_3],[AGE_GROUP] Like "*")=True;

Open in new window

0
 

Author Comment

by:Bob_Collison
Comment Utility
Hi Expert,
I'm not up to speed on SQL Code so I really need a solution using the Access Query Design Tool.
Thanks.
Bob C.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
Since you haven't told us the tablename and fields of the table containing the [AGE_GROUP] column, I can only suggest example SQL.

If you change the table name from "mytable" to your actual table name and switch from the SQL view to the QBE designer view, it should at least give you a first start.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
or post your database
0
 

Author Comment

by:Bob_Collison
Comment Utility
Hi Expert,

Below is the SQL Code for your reference.

In actual fact there are 15 tables in the query so the SQL is very long and complex.  The specific table where this field is located is [10_MEMBER_MSTR] which contains Organization Member records.  The [AGE_GROUP] field identifies whether the Member is an Adult (A) or a Youth (Y).

The way this works is that the Form is accessing one Member Record.  The User picks two Options (One or All) Members and Age Group (A (Adult), Y (Youth) or B (Both).  The parameters are written to the [00_PARAMETER_DATA] Table and the query links this table to the Member Master Table via a common field [GENERIC_LINK], extracts the data and displays it in the report.

The criteria other than that associated with the [AGE_GROUP] field work correctly.

SELECT [00_PARAMETER_DATA].USER_OBJECT_KEY, [00_PARAMETER_DATA].SYS_USER_KEY, [00_PARAMETER_DATA].OBJECT_KEY, [00_PARAMETER_DATA].ALPHA_PARM_1, [00_PARAMETER_DATA].ALPHA_PARM_2, [00_PARAMETER_DATA].ALPHA_PARM_3, [00_PARAMETER_DATA].PADDED_PERIOD_KEY, [10_MEMBER_MSTR].SYS_MEMBER_KEY, [PADDED_PERIOD_KEY] & [10_MEMBER_MSTR].SYS_MEMBER_KEY AS PERIOD_MEMBER_KEY, [10_MEMBER_MSTR].MMS_MEMBER_ID, [10_MEMBER_MSTR].CREATE_STAMP, [10_MEMBER_MSTR].SYS_MEMBER_RECORD_TYPE, [02_SYS_MEMBER_STATUS_MSTR].REG_STATUS_CD, [02_SYS_MEMBER_STATUS_MSTR].SHORT_NAME AS 02_SYS_MEMBER_STATUS_MSTR_SHORT_NAME, [10_MEMBER_MSTR].MMS_SCREEN_STATUS_CD, [02_MMS_SCREEN_STATUS_MSTR].LKUP_SHORT_NAME, [02_SYS_MEMBER_TYPE_MSTR].SYS_MEMBER_TYPE_CD, [10_MEMBER_MSTR].PRC_STATUS_CD, [02_SYS_PRC_STATUS_MSTR].SHORT_NAME, [10_MEMBER_MSTR].PRC_START_DATE, [10_MEMBER_MSTR].PRC_END_DATE, [10_MEMBER_MSTR].VSS_STATUS_CD, [02_SYS_PRC_STATUS_MSTR_1].SHORT_NAME, [10_MEMBER_MSTR].VSS_START_DATE, [10_MEMBER_MSTR].VSS_EXPIRY_DATE, [02_SYS_MEMBER_TYPE_MSTR].SHORT_NAME AS 02_SYS_MEMBER_TYPE_MSTR_SHORT_NAME, [10_MEMBER_MSTR].SALUTATION, [10_MEMBER_MSTR].SURNAME, [10_MEMBER_MSTR].FIRST_NAME, [10_MEMBER_MSTR].MIDDLE_NAME, [10_MEMBER_MSTR].INITIALS, [10_MEMBER_MSTR].NICKNAME, [10_MEMBER_MSTR].LANGUAGE_1, [10_MEMBER_MSTR].LANGUAGE_2, [10_MEMBER_MSTR].RELIGION, [10_MEMBER_MSTR].BIRTH_DATE, [10_MEMBER_MSTR].AGE, [10_MEMBER_MSTR].AGE_GROUP, [10_MEMBER_MSTR].LAST_SCHOOL, [10_MEMBER_MSTR].LAST_GRADE, [10_MEMBER_MSTR].HIGHEST_EDUCATION, [10_MEMBER_MSTR].GENDER_CD, [02_PARENTAL_ACCESS_MSTR].PARENTAL_ACCESS_CD, [02_PARENTAL_ACCESS_MSTR].SHORT_NAME AS 02_PARENTAL_ACCESS_MSTR_SHORT_NAME, [10_MEMBER_MSTR].PHOTO_CONSENT_CD, [10_MEMBER_MSTR].HOME_EMAIL_1, [10_MEMBER_MSTR].HOME_EMAIL_2, [10_MEMBER_MSTR].HOME_PHONE_1, [10_MEMBER_MSTR].HOME_PHONE_2, [10_MEMBER_MSTR].CELL_PHONE_1, [10_MEMBER_MSTR].HOME_ADDRESS_KEY, [03_GEO_ADDRESS_MSTR].ADDR_LN_1, [03_GEO_ADDRESS_MSTR].ADDR_LN_2, [03_GEO_ADDRESS_MSTR].ADDR_LN_3, [03_GEO_ADDRESS_MSTR].ADDR_LN_4, [03_GEO_ADDRESS_MSTR].ADDR_LN_5, [03_GEO_ADDRESS_MSTR].ADDR_LN_6, [10_MEMBER_MSTR].EMPLOYER_NAME, [10_MEMBER_MSTR].JOB_TITLE, [10_MEMBER_MSTR].WORK_ADDRESS_KEY, [03_GEO_ADDRESS_MSTR_1].ADDR_LN_1, [03_GEO_ADDRESS_MSTR_1].ADDR_LN_2, [03_GEO_ADDRESS_MSTR_1].ADDR_LN_3, [03_GEO_ADDRESS_MSTR_1].ADDR_LN_4, [03_GEO_ADDRESS_MSTR_1].ADDR_LN_5, [03_GEO_ADDRESS_MSTR_1].ADDR_LN_6, [10_MEMBER_MSTR].WORK_EMAIL_1, [10_MEMBER_MSTR].WORK_PHONE_1, [10_MEMBER_MSTR].WORK_PHONE_1_EXT, [10_MEMBER_MSTR].WORK_PHONE_2, [10_MEMBER_MSTR].WORK_PHONE_2_EXT, [10_MEMBER_MSTR].HEALTH_ID, [10_MEMBER_MSTR].MEDICAL_SUMMARY, [10_MEMBER_MSTR].MEDICAL_DETAILS, [10_MEMBER_MSTR].NOTES, [10_MEMBER_MSTR].CONTACT_1_KEY, [10_MEMBER_MSTR_1].SALUTATION AS C1_SALUTATION, [10_MEMBER_MSTR_1].SURNAME AS C1_SURNAME, [10_MEMBER_MSTR_1].FIRST_NAME AS C1_FIRST_NAME, [10_MEMBER_MSTR_1].MIDDLE_NAME AS C1_MIDDLE_NAME, [10_MEMBER_MSTR_1].INITIALS AS C1_INITIALS, [10_MEMBER_MSTR_1].HOME_PHONE_1 AS C1_HOME_PHONE_1, [10_MEMBER_MSTR].CONTACT_1_RELATIONSHIP, [10_MEMBER_MSTR].CONTACT_1_ADDRESS_KEY, [03_GEO_ADDRESS_MSTR_2].ADDR_LN_1, [03_GEO_ADDRESS_MSTR_2].ADDR_LN_2, [03_GEO_ADDRESS_MSTR_2].ADDR_LN_3, [03_GEO_ADDRESS_MSTR_2].ADDR_LN_4, [03_GEO_ADDRESS_MSTR_2].ADDR_LN_5, [03_GEO_ADDRESS_MSTR_2].ADDR_LN_6, [10_MEMBER_MSTR].CONTACT_2_KEY, [10_MEMBER_MSTR_2].SALUTATION AS C2_SALUTATION, [10_MEMBER_MSTR_2].SURNAME AS C2_SURNAME, [10_MEMBER_MSTR_2].FIRST_NAME AS C2_FIRST_NAME, [10_MEMBER_MSTR_2].MIDDLE_NAME AS C2_MIDDLE_NAME, [10_MEMBER_MSTR_2].INITIALS AS C2_INITIALS, [10_MEMBER_MSTR_2].HOME_PHONE_1 AS C2_HOME_PHONE_1, [10_MEMBER_MSTR].CONTACT_2_RELATIONSHIP, [10_MEMBER_MSTR].CONTACT_2_ADDRESS_KEY, [03_GEO_ADDRESS_MSTR_3].ADDR_LN_1, [03_GEO_ADDRESS_MSTR_3].ADDR_LN_2, [03_GEO_ADDRESS_MSTR_3].ADDR_LN_3, [03_GEO_ADDRESS_MSTR_3].ADDR_LN_4, [03_GEO_ADDRESS_MSTR_3].ADDR_LN_5, [03_GEO_ADDRESS_MSTR_3].ADDR_LN_6, [10_MEMBER_MSTR].BASE_REC
FROM (((((00_PARAMETER_DATA INNER JOIN (((((((10_MEMBER_MSTR LEFT JOIN 03_GEO_ADDRESS_MSTR ON [10_MEMBER_MSTR].HOME_ADDRESS_KEY = [03_GEO_ADDRESS_MSTR].ADDRESS_KEY) LEFT JOIN 02_SYS_MEMBER_STATUS_MSTR ON [10_MEMBER_MSTR].REG_STATUS_CD = [02_SYS_MEMBER_STATUS_MSTR].REG_STATUS_CD) LEFT JOIN 02_SYS_MEMBER_TYPE_MSTR ON [10_MEMBER_MSTR].SYS_MEMBER_TYPE = [02_SYS_MEMBER_TYPE_MSTR].SYS_MEMBER_TYPE_CD) LEFT JOIN 03_GEO_ADDRESS_MSTR AS 03_GEO_ADDRESS_MSTR_1 ON [10_MEMBER_MSTR].WORK_ADDRESS_KEY = [03_GEO_ADDRESS_MSTR_1].ADDRESS_KEY) LEFT JOIN 03_GEO_ADDRESS_MSTR AS 03_GEO_ADDRESS_MSTR_2 ON [10_MEMBER_MSTR].CONTACT_1_ADDRESS_KEY = [03_GEO_ADDRESS_MSTR_2].ADDRESS_KEY) LEFT JOIN 03_GEO_ADDRESS_MSTR AS 03_GEO_ADDRESS_MSTR_3 ON [10_MEMBER_MSTR].CONTACT_2_ADDRESS_KEY = [03_GEO_ADDRESS_MSTR_3].ADDRESS_KEY) LEFT JOIN 02_PARENTAL_ACCESS_MSTR ON [10_MEMBER_MSTR].PARENTAL_ACCESS_CD = [02_PARENTAL_ACCESS_MSTR].PARENTAL_ACCESS_CD) ON [00_PARAMETER_DATA].GENERIC_LINK = [10_MEMBER_MSTR].GENERIC_LINK) LEFT JOIN 10_MEMBER_MSTR AS 10_MEMBER_MSTR_1 ON [10_MEMBER_MSTR].CONTACT_1_KEY = [10_MEMBER_MSTR_1].SYS_MEMBER_KEY) LEFT JOIN 10_MEMBER_MSTR AS 10_MEMBER_MSTR_2 ON [10_MEMBER_MSTR].CONTACT_2_KEY = [10_MEMBER_MSTR_2].SYS_MEMBER_KEY) LEFT JOIN 02_SYS_PRC_STATUS_MSTR ON [10_MEMBER_MSTR].PRC_STATUS_CD = [02_SYS_PRC_STATUS_MSTR].PRC_STATUS_CD) LEFT JOIN 02_SYS_PRC_STATUS_MSTR AS 02_SYS_PRC_STATUS_MSTR_1 ON [10_MEMBER_MSTR].VSS_STATUS_CD = [02_SYS_PRC_STATUS_MSTR_1].PRC_STATUS_CD) LEFT JOIN 02_MMS_SCREEN_STATUS_MSTR ON [10_MEMBER_MSTR].MMS_SCREEN_STATUS_CD = [02_MMS_SCREEN_STATUS_MSTR].MMS_SCREEN_STATUS_CD
WHERE ((([00_PARAMETER_DATA].USER_OBJECT_KEY)=[Forms]![M-00-000 - Scout Admin System - Main Menu]![F-00-001 - System User Lookup SubForm].[Form]![SYS_USER_KEY] & "R-10-210**") AND (([10_MEMBER_MSTR].SYS_MEMBER_KEY)=IIf([00_PARAMETER_DATA].[ALPHA_PARM_1]="All",[10_MEMBER_MSTR].[SYS_MEMBER_KEY],[00_PARAMETER_DATA].[ALPHA_PARM_2])) AND (([10_MEMBER_MSTR].SYS_MEMBER_RECORD_TYPE)="PER") AND (([10_MEMBER_MSTR].AGE_GROUP)=IIf([00_PARAMETER_DATA].[ALPHA_PARM_3]="B",([10_MEMBER_MSTR].AGE_GROUP) Like "*",[00_PARAMETER_DATA].[ALPHA_PARM_3])));

Thanks.
Bob C.
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
Comment Utility
Please try this version of your WHERE clause:
WHERE ((([00_PARAMETER_DATA].USER_OBJECT_KEY)=[Forms]![M-00-000 - Scout Admin System - Main Menu]![F-00-001 - System User Lookup SubForm].[Form]![SYS_USER_KEY] & "R-10-210**")
 AND (([10_MEMBER_MSTR].SYS_MEMBER_KEY)=IIf([00_PARAMETER_DATA].[ALPHA_PARM_1]="All",[10_MEMBER_MSTR].[SYS_MEMBER_KEY],[00_PARAMETER_DATA].[ALPHA_PARM_2])) AND (([10_MEMBER_MSTR].SYS_MEMBER_RECORD_TYPE)="PER") AND 
 (IIf([00_PARAMETER_DATA].[ALPHA_PARM_3] In ("A","Y"),[10_MEMBER_MSTR].[AGE_GROUP]=[00_PARAMETER_DATA].[ALPHA_PARM_3],[10_MEMBER_MSTR].[AGE_GROUP] Like "*")=True) );

Open in new window

0
 

Author Closing Comment

by:Bob_Collison
Comment Utility
Hi Expert,
Your solution does work but it doesn't address how to configure it using Access Query Design for those of us who don't know SQL.
Thanks.
Bob C.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
There are some things that the query design wizard can not help.  One of them is writing complex expressions, such as your IIF() function.  The IIF() function comes out of the VB environment.  If you want to know more about this, then the VB language is what you should study.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Bob_Collison
Comment Utility
Hi Experts,
Having read you comments and the Grading Criteria I agree that 'B' is the correct grading.
Thanks.
Bob C.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
Looking at my IIF() function again, I realized it could be simplified as follows.  The false clause really only needs to be a constant TRUE value.  This should perform better.
WHERE ((([00_PARAMETER_DATA].USER_OBJECT_KEY)=[Forms]![M-00-000 - Scout Admin System - Main Menu]![F-00-001 - System User Lookup SubForm].[Form]![SYS_USER_KEY] & "R-10-210**")
 AND (([10_MEMBER_MSTR].SYS_MEMBER_KEY)=IIf([00_PARAMETER_DATA].[ALPHA_PARM_1]="All",[10_MEMBER_MSTR].[SYS_MEMBER_KEY],[00_PARAMETER_DATA].[ALPHA_PARM_2])) AND (([10_MEMBER_MSTR].SYS_MEMBER_RECORD_TYPE)="PER") AND 
 (IIf([00_PARAMETER_DATA].[ALPHA_PARM_3] In ("A","Y"),[10_MEMBER_MSTR].[AGE_GROUP]=[00_PARAMETER_DATA].[ALPHA_PARM_3],True)=True) );

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
Why not an A?

When Bob wrote,
What should the syntax be?
my solution comment was exactly the syntax required.
0
 

Author Comment

by:Bob_Collison
Comment Utility
Hi Experts,
Although this worked and I can use it I can't figure out how to do another query that is very similar, so although it provided the correct result in my opinion the syntax is not understandable / re-usable by me.
Thanks.
Bob C.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
until you master the subject material, you will need to post new questions for every new query.
0
 

Author Comment

by:Bob_Collison
Comment Utility
OK
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
@Bob

The query wizard is a graphical user interface (dialog window) that actually creates SQL.  If the SQL gets too complicated to render in the query wizard, you have to alter the SQL text without a GUI.  Union queries are one type of query that can't be created/altered in the query wizard.

You should be able to open up the query in the query wizard and learn how my solution SQL is rendered in the query wizard.  It will most likely be reflected in the bottom half of the grid.

Right clicking on some of the cells should display a pop-up menu.  Look for the Build menu item.  If you need help creating expressions, such as an IIF() function, this might be the place to start in the query wizard.

====================
Even if you had posted your database, the query wizard is not a window that can stay open during file transfer.  The query wizard is not a mechanism with which an expert can communicate a solution to you on EE.
0
 

Author Comment

by:Bob_Collison
Comment Utility
Hi Expert,
Thanks for the information.
Bob C.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

16 Experts available now in Live!

Get 1:1 Help Now