Update query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

They scare me! I do have a copy of the db.

Here's what I'm trying to say:

Find Contacts who are Board Members and make them Gala Members as well.

Here's my query to find Board Members:
SELECT Contacts.LastName, Contacts.ContactID
FROM Contacts INNER JOIN (Groups INNER JOIN GroupMembers ON Groups.GroupID =
GroupMembers.GroupID) ON Contacts.ContactID = GroupMembers.ContactID
WHERE (((Groups.GroupName)="Board of Directors") AND
((GroupMembers.GMemberEnd) Is Null));

The Groups.GroupID for "Gala" is 12.
GroupMembers contains: GroupMemberID, GroupID, ContactID,GMemberEnd

Here's what I'm thinking so far:
UPDATE GroupMembers SET GroupMembers.GroupID = 12
WHERE (((Groups.GroupName)="Board of Directors") AND
((GroupMembers.GMemberEnd) Is Null));

But I've seem to have lost the ContactID info. And I want to make sure that
I'm not going to overwrite "Board of Directors" with "Gala"...

I'd appreciate your suggestions.
 
Looks to me as if you want to add a new record to GroupMembers (append) and
not UPDATE an existing record.

You should be able to use your first query as the source for the append
query. Something like
INSERT INTO GroupMembers (GroupID, ContactID)
SELECT "12" as GroupID, Contacts.ContactID
FROM Contacts INNER JOIN
(Groups INNER JOIN GroupMembers
ON Groups.GroupID = GroupMembers.GroupID)
ON Contacts.ContactID = GroupMembers.ContactID
WHERE (((Groups.GroupName)="Board of Directors") AND
((GroupMembers.GMemberEnd) Is Null));

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
John,

Thanks for the reply and the lesson! I'll give it a try.
My query snip is from a union query that has 3 queries in it. Would I be
better off running the entire union query, or should I separate the queries?
I'm a bit worried that I may append a Contact's group more than once if I
run the queries separately...

Have a great weekend!
 
Try it and see if it works. Although with the union query you will
probably need to save the union query and then use the saved query as
the source.

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
Back
Top