RE/
SELECT tblFriend.PersonID AS Person, tblFriend.FriendID AS Friend
FROM tblFriend UNION ALL SELECT tblFriend.FriendID AS Person,
tblFriend.PersonID AS Friend
FROM tblFriend;
that should get you a list of Person to Friend and the reverse
relationship you are looking for.
Now the half baked part...
I assume you will make a form to show the person data, with a subform
showing friends. The subform will use the union query as the record
source. You will have to manage adding and deleting relationships via
popups since you can't do that directly in the union query. Shouldn't
be a big deal but I'm sure there will be gotchas in there somewhere.
I'd be interested in the gotchas you run across if you use it. If you
don't I'd like to hear why you rejected the approach.
Done. Works as advertised.
-----------------------
tblPersonFriend:
PersonFriendID (PK)
PersonID_A
PersonID_B
Comments
-----------------------
The union query returns tblFriend recs where PersonID_A
matches the currently-selected person and where PersonID_B matches same.
I feed the Union query to an Append query that loads that info into a work
table, putting PersonID_A or ..._B into the work table's PersonID as appropriate
and putting the other into FriendID. The subform's combo box's.ControlSource is
FriendID and it's .RowSource is a list of people by PersonID, excluding
whoever's record is currently being edited.
------------------
ttblFriend:
PersonFriendID
PersonID
FriendID
Comments
------------------
When Save time comes around, I run four queries:
- qryPersonSave_Friend1_AppendNew
- qryPersonSave_Friend2_UpdateExisting
- qryPersonSave_Friend3_IdentifyDeleted
- qryPersonSave_Friend4_RemoveDeleted
There's a little more processing with deleted recs.
This comes in the form of another work table that I didn't mention yet:
------------------------
ttblFriendDeleteTracker:
PersonFriendID
IsDeleted
------------------------
Right after I load ttblFriend, I load ttblFriendDeleteTracker
by copying info from the just-loaded ttblFriend.
Then, at Save time, I run an Update query that joins ttblPersonFriend to
ttblPersonFriendDeleteTracker on PersonFriendID and sets IsDeleted=True for recs
that have disappeared from ttblPersonFriend.
After that's done, I run a Delete query that joins ttblPersonFriendDeleteTracker
to tblPersonFriend on PersonFriendID and deletes tblPersonFriend recs where
IsDeleted=True.
Sounds like a lot of code, but it's pretty simple and executes in a flash.
Thanks.
--
PeteCresswell