Print Page | Close Window

SQL Help Needed

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=4663
Printed Date: 30 March 2026 at 5:41am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: SQL Help Needed
Posted By: Aljrob
Subject: SQL Help Needed
Date Posted: 01 August 2003 at 5:11am

Hi everyone, hope someone will be able to help me!  I'm developing this database in Access, but I think the problem's primarily an SQL one.

I have the following table structure in place -

Quote:

tblContact
ContactID (Autonumber, P.K.)
Name (Text)

tblContactBenchMarkLink
ID (Autonumber, P.K.)
ContactID (Number, one to many from tblContact)
BenchmarkID (Number, One to many from tblBenchmark)

tblBenchmark
ID (P.K., autonumber)
Benchmark (text)



And I also have a combo box on a subform that uses the following recordsource to do its magic:

Quote:

SELECT [tblBenchmark].[BenchmarkID], [tblBenchmark].[Benchmark] FROM tblBenchmark;



Now, the data from tblBenchmark, benchmarkID and Benchmark should only be linked to a contactID (via tblContactBenchMarkLink) ONCE.

What I want to do is use some code, perhaps via the form_current event, to requery the combo box to NOT include benchmarks that already have a record in tblContactBenchMarkLink for the current contact.

For example, if there are:
4 benchmarks - power (BenchMarkID=1), top_speed (2), standard_equipment (3) and fuel_economy (4)
2 contacts - Bob (ContactID=1) & Sam (2)

and tblContactBenchMarkLink contains two records -
ID 1, ContactID 2, BenchmarkID 2
ID2, ContactID 2, BenchmarkID 3

The next time I select Sam's record, and click on the combo box that allows me to select his benchmarks in a new record in tblContactBenchMarkLink, I want only power and fuel_economy to appear, since I've already told the db that Sam cares about top_speed and standard_equipment.

Does anyone know if this is possible, and if so, how to go about it? I think it's probably just a case of updating the recordsource property of the combo when the form's current, but I'm not sure how to write this sql string.

  • Here's the thing I need to do then - select BenchMarkID and Benchmark fields from tblBenchmark when the records corresponding to a particular contact in tblContactBenchmarkLink do NOT contain the BenchmarkID

Here's hoping someone knows of a solution!

Thx in advance,

Aljrob




Replies:
Posted By: Morgan
Date Posted: 02 August 2003 at 9:40pm

I'm assuming you meant for the ID in tblBenchmark to be BenchmarkID.  For the SQL statement, try:

SELECT tblBenchmark.BenchmarkID,  tblBenchmark.Benchmark
FROM tblBenchmark
WHERE tblBenchmark.BenchmarkID NOT IN
(SELECT tblContactBenchmarkLink.BenchmarkID
FROM tblContactBenchmarkLink
WHERE ContactID = 2);

The 2 can be a variable which stores the ContactID of the person you are viewing.



-------------
Morgan


Posted By: Aljrob
Date Posted: 04 August 2003 at 2:39am
Thanks, works a treat



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net