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 » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Update Query!



 
 
Thread Tools Display Modes
  #1  
Old March 9th, 2010, 10:44 PM posted to microsoft.public.access
Bob Vance
external usenet poster
 
Posts: 726
Default Update Query!


Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices
--
Thanks in advance for any help with this......Bob
MS Access 2007 accdb
Windows XP Home Edition Ver 5.1 Service Pack 3


  #2  
Old March 9th, 2010, 11:02 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Update Query!

On Wed, 10 Mar 2010 11:44:17 +1300, "Bob Vance" wrote:


Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices


You probably need three queries, one for each table. They can be run in
sequence from a Macro or from VBA code.

If you have cascading deletes set up on the relationships between your table -
e.g. tblHorses is related one to many to tblOwners, with the Cascade Deletes
checkbox set, and similarly for tblInvoices - then deleting a record from
tblOwners will delete all the records for that owner from the other two
tables. It won't "delete the content of the fields" - it will remove the
entire record leaving no trace that it was there.

(Be sure you have a backup!!!!! Deletion is a one-way street!)
--

John W. Vinson [MVP]
  #3  
Old March 9th, 2010, 11:02 PM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Update Query!

Bob:

If by 'delete all contents' you mean leave the rows in place but with Nulls
in all columns (which is what your reference to an UPDATE query would suggest)
, the answer is No, or more accurately it is if the table definitions are
legitimate, as no primary key or part thereof can be Null.

You could delete all rows from all three tables with a single DELETE query if
cascade deletes were enforced in the relationships from owners to horses and
owners to invoices (assuming only one owner per horse), but I think that
would be rather dangerous. If you need to empty all three tables I'd be
inclined to enforce referential integrity and then execute three DELETE
queries, horses and invoices first, then owners.

Ken Sheridan
Stafford, England

Bob Vance wrote:
Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices


--
Message posted via http://www.accessmonster.com

  #4  
Old March 10th, 2010, 04:20 AM posted to microsoft.public.access
Bob Vance
external usenet poster
 
Posts: 726
Default Update Query!

Well actually I have 25 tables and want to delete the contents of 20 of them
to form a empty database that my friends can use without my data in it, so i
should still look at cascade delete...Thanks bob

"KenSheridan via AccessMonster.com" u51882@uwe wrote in message
news:a4c56d1f35877@uwe...
Bob:

If by 'delete all contents' you mean leave the rows in place but with
Nulls
in all columns (which is what your reference to an UPDATE query would
suggest)
, the answer is No, or more accurately it is if the table definitions are
legitimate, as no primary key or part thereof can be Null.

You could delete all rows from all three tables with a single DELETE query
if
cascade deletes were enforced in the relationships from owners to horses
and
owners to invoices (assuming only one owner per horse), but I think that
would be rather dangerous. If you need to empty all three tables I'd be
inclined to enforce referential integrity and then execute three DELETE
queries, horses and invoices first, then owners.

Ken Sheridan
Stafford, England

Bob Vance wrote:
Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices


--
Message posted via http://www.accessmonster.com



  #5  
Old March 10th, 2010, 04:54 AM posted to microsoft.public.access
PieterLinden via AccessMonster.com
external usenet poster
 
Posts: 307
Default Update Query!

Bob Vance wrote:
Well actually I have 25 tables and want to delete the contents of 20 of them
to form a empty database that my friends can use without my data in it, so i
should still look at cascade delete...Thanks bob

Bob:

[quoted text clipped - 21 lines]
tblOwners
tblInvoices


Being disgustingly lazy, I would probably do something like:
1. create a query to get the list of tables from the database.
2. loop through the records returned and run some dynamic SQL to delete the
contents of the table.

something like...

Sub DeleteContentsOfTables()
dim rsT as dao.recordset
dim strTables as string

' define the list of tables
' the NOT IN clause is to skip over the tables I want to keep...

strTables = "SELECT MSysObjects.Name FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like 'MSys*') AND ((MSysObjects.Type)=1)
AND MSysObjects.Name NOT IN ('Keep This One', 'Keep That One'));"

' Open a recordset of tables to delete so they can be processed one at a time
set rsT = DBEngine(0)(0).OpenRecordset strTables, dbOpenForwardOnly
Do until rsT.EOF
' delete the contents of the table.
DBEngine(0)(0).Execute "DELETE * FROM [" & rsT.Name & "]", dbFailOnError
rsT.MoveNext
Loop

rsT.close
set rsT = nothing

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201003/1

  #6  
Old March 10th, 2010, 05:36 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Update Query!

On Wed, 10 Mar 2010 17:20:37 +1300, "Bob Vance" wrote:

Well actually I have 25 tables and want to delete the contents of 20 of them
to form a empty database that my friends can use without my data in it, so i
should still look at cascade delete...Thanks bob


There's an easier way!

Create a new empty database, and use File... Get External Data... Import to
import all 25 tables. For the ones you want empty, check the box "design view
only"; for the rest, check "structure and data".

--

John W. Vinson [MVP]
  #7  
Old March 13th, 2010, 05:33 PM posted to microsoft.public.access
De Jager
external usenet poster
 
Posts: 393
Default Update Query!


"Bob Vance" wrote in message
...

Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices
--
Thanks in advance for any help with this......Bob
MS Access 2007 accdb
Windows XP Home Edition Ver 5.1 Service Pack 3



  #8  
Old March 17th, 2010, 01:09 PM posted to microsoft.public.access
joelgeraldine
external usenet poster
 
Posts: 201
Default Update Query!

yj;:!§

"Bob Vance" a écrit dans le message de groupe de
discussion : ...

Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices
--
Thanks in advance for any help with this......Bob
MS Access 2007 accdb
Windows XP Home Edition Ver 5.1 Service Pack 3


  #9  
Old March 17th, 2010, 01:19 PM posted to microsoft.public.access
joelgeraldine
external usenet poster
 
Posts: 201
Default Update Query!

ykkklmmmmùùùùù**




"Bob Vance" a écrit dans le message de groupe de
discussion : ...

Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices
--
Thanks in advance for any help with this......Bob
MS Access 2007 accdb
Windows XP Home Edition Ver 5.1 Service Pack 3


  #10  
Old May 24th, 2010, 07:12 PM posted to microsoft.public.access
matteo
external usenet poster
 
Posts: 7
Default Update Query!


"Bob Vance" ha scritto nel messaggio
...

Can I have an UpDate query to delete all content of all fields in
tblHorses
tblOwners
tblInvoices
--
Thanks in advance for any help with this......Bob
MS Access 2007 accdb
Windows XP Home Edition Ver 5.1 Service Pack 3



 




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


All times are GMT +1. The time now is 03:35 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.