A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"Cannot delete from specified tables"



 
 
Thread Tools Display Modes
  #1  
Old November 10th, 2005, 07:12 PM
external usenet poster
 
Posts: n/a
Default "Cannot delete from specified tables"

Hello!


Here is part of my database:


tblStudents: StudentID
tblStudentsAndMajors: StudentID, MajorID
tblMajors: MajorID
tblMajorsAndClasses: MajorID, ClassID
tblClasses: ClassID
tblStudentsAndClasses: StudentID, ClassID, QuarterTaken

In my form, when I remove a major from a student, I want it to delete
two things:
- in tblStudentsAndMajors: remove the record where StudentID (11 as a
test) and MajorID (2 as a test) match StudentID and MajorID from the
form
- in tblStudensAndClasses: remove the records where StudentID and
MajorID match StudentID and MajorID from the form, and where
QuarterTaken is false


DELETE [Students And Majors].*, [Students And Classes].*
FROM (Majors
INNER JOIN ((Classes
INNER JOIN [Classes And Majors]
ON Classes.ClassID = [Classes And Majors].ClassID)
INNER JOIN [Students And Classes]
ON Classes.ClassID = [Students And Classes].ClassID)
ON Majors.MajorID = [Classes And Majors].MajorID)
INNER JOIN [Students And Majors]
ON Majors.MajorID = [Students And Majors].MajorID
WHERE ((([Students And Classes].StudentID)=11)
AND (([Students And Classes].Taken)=False)
AND (([Students And Majors].StudentID)=11)
AND (([Students And Majors].MajorID)=2));

When I do that query, the datasheet view gives me the results I want
(all the line to delete), but if I run the query, I get "Cannot delete
from specified tables".

Does anyone has an idea?

Thanks,
Celine

  #2  
Old November 10th, 2005, 07:41 PM
Amy Blankenship
external usenet poster
 
Posts: n/a
Default "Cannot delete from specified tables"

What you probably actually want to do is just make the major inactive (add
an IsActive field) and then add a new record for the new major.

Rather than adding fields for classes the student hasn't taken yet, you
should probably just display the classes they *should* take as a view in a
query. Only add the class when the class is actually taken or at least
scheduled.

So then when they switch majors, the query will show the classes they
*should* take for the new major, and the old major's records, since they
never actually existed, don't show up. If you want to show both classes the
student *has* taken and classes they *should* take, you'd want to use a
union query of the should take query and tblStudentsAndClasses.

HTH;

Amy

wrote in message
oups.com...
Hello!


Here is part of my database:


tblStudents: StudentID
tblStudentsAndMajors: StudentID, MajorID
tblMajors: MajorID
tblMajorsAndClasses: MajorID, ClassID
tblClasses: ClassID
tblStudentsAndClasses: StudentID, ClassID, QuarterTaken

In my form, when I remove a major from a student, I want it to delete
two things:
- in tblStudentsAndMajors: remove the record where StudentID (11 as a
test) and MajorID (2 as a test) match StudentID and MajorID from the
form
- in tblStudensAndClasses: remove the records where StudentID and
MajorID match StudentID and MajorID from the form, and where
QuarterTaken is false


DELETE [Students And Majors].*, [Students And Classes].*
FROM (Majors
INNER JOIN ((Classes
INNER JOIN [Classes And Majors]
ON Classes.ClassID = [Classes And Majors].ClassID)
INNER JOIN [Students And Classes]
ON Classes.ClassID = [Students And Classes].ClassID)
ON Majors.MajorID = [Classes And Majors].MajorID)
INNER JOIN [Students And Majors]
ON Majors.MajorID = [Students And Majors].MajorID
WHERE ((([Students And Classes].StudentID)=11)
AND (([Students And Classes].Taken)=False)
AND (([Students And Majors].StudentID)=11)
AND (([Students And Majors].MajorID)=2));

When I do that query, the datasheet view gives me the results I want
(all the line to delete), but if I run the query, I get "Cannot delete
from specified tables".

Does anyone has an idea?

Thanks,
Celine



  #3  
Old November 10th, 2005, 08:04 PM
external usenet poster
 
Posts: n/a
Default "Cannot delete from specified tables"

Thank you, I am going to try that, it sound like a really good idea!

  #4  
Old November 10th, 2005, 08:20 PM
John Spencer
external usenet poster
 
Posts: n/a
Default "Cannot delete from specified tables"

You cannot delete from two tables in one query.

You will have to split the delete into two separate queries.


wrote in message
oups.com...
Hello!


Here is part of my database:


tblStudents: StudentID
tblStudentsAndMajors: StudentID, MajorID
tblMajors: MajorID
tblMajorsAndClasses: MajorID, ClassID
tblClasses: ClassID
tblStudentsAndClasses: StudentID, ClassID, QuarterTaken

In my form, when I remove a major from a student, I want it to delete
two things:
- in tblStudentsAndMajors: remove the record where StudentID (11 as a
test) and MajorID (2 as a test) match StudentID and MajorID from the
form
- in tblStudensAndClasses: remove the records where StudentID and
MajorID match StudentID and MajorID from the form, and where
QuarterTaken is false


DELETE [Students And Majors].*, [Students And Classes].*
FROM (Majors
INNER JOIN ((Classes
INNER JOIN [Classes And Majors]
ON Classes.ClassID = [Classes And Majors].ClassID)
INNER JOIN [Students And Classes]
ON Classes.ClassID = [Students And Classes].ClassID)
ON Majors.MajorID = [Classes And Majors].MajorID)
INNER JOIN [Students And Majors]
ON Majors.MajorID = [Students And Majors].MajorID
WHERE ((([Students And Classes].StudentID)=11)
AND (([Students And Classes].Taken)=False)
AND (([Students And Majors].StudentID)=11)
AND (([Students And Majors].MajorID)=2));

When I do that query, the datasheet view gives me the results I want
(all the line to delete), but if I run the query, I get "Cannot delete
from specified tables".

Does anyone has an idea?

Thanks,
Celine



  #5  
Old November 10th, 2005, 09:08 PM
Adam Turner via AccessMonster.com
external usenet poster
 
Posts: n/a
Default "Cannot delete from specified tables"

wrote:
Hello!

Here is part of my database:

tblStudents: StudentID
tblStudentsAndMajors: StudentID, MajorID
tblMajors: MajorID
tblMajorsAndClasses: MajorID, ClassID
tblClasses: ClassID
tblStudentsAndClasses: StudentID, ClassID, QuarterTaken

In my form, when I remove a major from a student, I want it to delete
two things:
- in tblStudentsAndMajors: remove the record where StudentID (11 as a
test) and MajorID (2 as a test) match StudentID and MajorID from the
form
- in tblStudensAndClasses: remove the records where StudentID and
MajorID match StudentID and MajorID from the form, and where
QuarterTaken is false

DELETE [Students And Majors].*, [Students And Classes].*
FROM (Majors
INNER JOIN ((Classes
INNER JOIN [Classes And Majors]
ON Classes.ClassID = [Classes And Majors].ClassID)
INNER JOIN [Students And Classes]
ON Classes.ClassID = [Students And Classes].ClassID)
ON Majors.MajorID = [Classes And Majors].MajorID)
INNER JOIN [Students And Majors]
ON Majors.MajorID = [Students And Majors].MajorID
WHERE ((([Students And Classes].StudentID)=11)
AND (([Students And Classes].Taken)=False)
AND (([Students And Majors].StudentID)=11)
AND (([Students And Majors].MajorID)=2));

When I do that query, the datasheet view gives me the results I want
(all the line to delete), but if I run the query, I get "Cannot delete
from specified tables".

Does anyone has an idea?

Thanks,
Celine


You can't delete from a joined table...

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200511/1
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
delete Rich1234 Using Forms 3 October 10th, 2005 02:37 PM
How can I DELETE a CONTACT from the Contacts Folder without an Err Frustrated & Fuming in Fairview Contacts 1 July 5th, 2005 08:52 PM
deleting values in combo boxes R General Discussion 23 November 19th, 2004 02:30 PM
Delete Query Shanin Running & Setting Up Queries 14 July 31st, 2004 07:15 PM
Delete - confirmation required Elfie General Discussion 2 May 21st, 2004 05:51 PM


All times are GMT +1. The time now is 12:07 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.