Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Access update statement with subquery in the set clause?

Posted on 2007-12-02
3
Medium Priority
?
4,675 Views
Last Modified: 2012-05-05
Experts,
I am trying to run the following update this update statement works:

UPDATE MJM_ATTEND_PAY_INDIV SET MJM_ATTEND_PAY_INDIV.ATTEND_PER_MONTH = 4
WHERE (((MJM_ATTEND_PAY_INDIV.ROW_ID) In (SELECT [MJM_ATTEND_PAY_INDIV].[ROW_ID]
FROM MJM_SCHOOL, MJM_CLASS, MJM_STUDENT, MJM_ATTEND_PAY_INDIV
WHERE [MJM_SCHOOL].[ROW_ID]=[MJM_CLASS].[SCHOOL_ID] And
[MJM_CLASS].[ROW_ID]=[MJM_STUDENT].[CLASS_ID] And
[MJM_STUDENT].[ROW_ID]=[MJM_ATTEND_PAY_INDIV].[STUDENT_ID] And
[MJM_STUDENT].[ACTIVE_FLG] = -1 And  
[MJM_ATTEND_PAY_INDIV].[PAID_FLG]=0 And
[MJM_SCHOOL].[ROW_ID] IN (select row_id  from mjm_school as sc where sc.active_flg = -1 and sc.billing_flg = -1 and sc.payment_type = 'Individual') And
[MJM_ATTEND_PAY_INDIV].[BILLING_MONTH]=[Date])));

However instead of hardcoding the number 4 at the end of the set statement, I want to use a subselect:

UPDATE MJM_ATTEND_PAY_INDIV SET MJM_ATTEND_PAY_INDIV.ATTEND_PER_MONTH = (select config_value from mjm_lu_config where config_type = 'Week Override')
WHERE (((MJM_ATTEND_PAY_INDIV.ROW_ID) In (SELECT [MJM_ATTEND_PAY_INDIV].[ROW_ID]
FROM MJM_SCHOOL, MJM_CLASS, MJM_STUDENT, MJM_ATTEND_PAY_INDIV
WHERE [MJM_SCHOOL].[ROW_ID]=[MJM_CLASS].[SCHOOL_ID] And
[MJM_CLASS].[ROW_ID]=[MJM_STUDENT].[CLASS_ID] And
[MJM_STUDENT].[ROW_ID]=[MJM_ATTEND_PAY_INDIV].[STUDENT_ID] And
[MJM_STUDENT].[ACTIVE_FLG] = -1 And  
[MJM_ATTEND_PAY_INDIV].[PAID_FLG]=0 And
[MJM_SCHOOL].[ROW_ID] IN (select row_id  from mjm_school as sc where sc.active_flg = -1 and sc.billing_flg = -1 and sc.payment_type = 'Individual') And
[MJM_ATTEND_PAY_INDIV].[BILLING_MONTH]=[Date])));

I know the subselect only returns 1 row.  However, when I do this I get an error that says "query must be updateable".

I would think I would be able to do this, am I doing something wrong?

Thank you in advance for the help.

- Mike
0
Comment
Question by:uconnfb13
  • 2
3 Comments
 
LVL 75
ID: 20391776
I'm not sure you can use a sub selelect stmt in the SET part of an update query.

mx
0
 
LVL 75
ID: 20391782
Possibly a DLookup instead ?

mx
0
 
LVL 16

Accepted Solution

by:
Rick_Rickards earned 1600 total points
ID: 20392213
PARAMETERS [Week Overide] Text ( 255 );
UPDATE MJM_ATTEND_PAY_INDIV SET MJM_ATTEND_PAY_INDIV.ATTEND_PER_MONTH = (select config_value from mjm_lu_config where config_type = [Week Override])
WHERE (((MJM_ATTEND_PAY_INDIV.ROW_ID) In (SELECT [MJM_ATTEND_PAY_INDIV].[ROW_ID]
FROM MJM_SCHOOL, MJM_CLASS, MJM_STUDENT, MJM_ATTEND_PAY_INDIV
WHERE [MJM_SCHOOL].[ROW_ID]=[MJM_CLASS].[SCHOOL_ID] And
[MJM_CLASS].[ROW_ID]=[MJM_STUDENT].[CLASS_ID] And
[MJM_STUDENT].[ROW_ID]=[MJM_ATTEND_PAY_INDIV].[STUDENT_ID] And
[MJM_STUDENT].[ACTIVE_FLG] = -1 And  
[MJM_ATTEND_PAY_INDIV].[PAID_FLG]=0 And
[MJM_SCHOOL].[ROW_ID] IN (select row_id  from mjm_school as sc where sc.active_flg = -1 and sc.billing_flg = -1 and sc.payment_type = 'Individual') And
[MJM_ATTEND_PAY_INDIV].[BILLING_MONTH]=[Date])));
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

916 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