Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL Help Needed
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL Help Needed

 Post Reply Post Reply
Author
Aljrob View Drop Down
Newbie
Newbie
Avatar

Joined: 01 August 2003
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aljrob Quote  Post ReplyReply Direct Link To This Post Topic: SQL Help Needed
    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

Back to Top
Morgan View Drop Down
Groupie
Groupie


Joined: 13 September 2002
Location: United States
Status: Offline
Points: 114
Post Options Post Options   Thanks (0) Thanks(0)   Quote Morgan Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Aljrob View Drop Down
Newbie
Newbie
Avatar

Joined: 01 August 2003
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aljrob Quote  Post ReplyReply Direct Link To This Post Posted: 04 August 2003 at 2:39am
Thanks, works a treat
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.