Using Minus operator

aman

Registered User.
Local time
Yesterday, 22:58
Joined
Oct 16, 2008
Messages
1,251
The HeadingID,HeadingName are stored in lkupHeadings.

The HeadingID,Goals,Measures,Weighting,Staffnumber,DateFrom,DateTo etc are stored in lkupObjectives.

Now I am writing the following code;

Code:
 Dim strsql As String
strsql = "(select Headingid from lkupHeadings) minus (select HeadingID from lkupobjectives where [StaffNumber]='" & Environ("Username") & "')"
 MsgBox strsql
 CboHeading.RowSource = strsql

This gives me "Syntex error in Union query".

Any help will be much appreciated

Thanks
 
You can try this :
strsql = "select HeadingID from lkupHeadings where NOT EXISTS (select HeadingID from lkupobjectives where lkupobjectives.HeadingID = lkupHeadings.HeadingID [StaffNumber]='" & Environ("Username") & "'"

Or NOT IN or just a plain old left join.

In any case, Access doesn't support MINUS...
 
Or:

Dim strsql As String
strsql = "(select Headingid from lkupHeadings) Where HeadingID Not In (select HeadingID from lkupobjectives where [StaffNumber]='" & Environ("Username") & "')"
MsgBox strsql
CboHeading.RowSource = strsql
 

Users who are viewing this thread

Back
Top Bottom