PC Review


Reply
Thread Tools Rate Thread

Delete all Records

 
 
Eric
Guest
Posts: n/a
 
      22nd Aug 2008
I run append queries from a 4 temporary tables to 4 permanent tables. After
the append, I'd like to run a Delete Query after the append queries, that
will delete all records in all 4 temporary tables.

I've looked at some ideas and code from others, but I'm not needing any
fault attributes. I am sure of the append functions and am sure I want the
records deleted.

Here is some code I am trying with only two tables, but I get an error "you
can not delete from the specified tables"

DELETE [1ReviewHDR].*, [2ReviewBPS].*
FROM 2ReviewBPS, 1ReviewHDR;

Any help would be great.

--
Eric the Rookie
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      22nd Aug 2008
"Eric" <(E-Mail Removed)> wrote in message
news:309B8AEE-E5FD-4A3B-9CE9-(E-Mail Removed)...
>I run append queries from a 4 temporary tables to 4 permanent tables.
>After
> the append, I'd like to run a Delete Query after the append queries, that
> will delete all records in all 4 temporary tables.
>
> I've looked at some ideas and code from others, but I'm not needing any
> fault attributes. I am sure of the append functions and am sure I want
> the
> records deleted.
>
> Here is some code I am trying with only two tables, but I get an error
> "you
> can not delete from the specified tables"
>
> DELETE [1ReviewHDR].*, [2ReviewBPS].*
> FROM 2ReviewBPS, 1ReviewHDR;



You can only delete from one table at a time. You'll have to run 4 delete
queries; e.g.,

With CurrentDb
.Execute "DELETE FROM [1ReviewHDR]", dbFailOnError
.Execute "DELETE FROM [2ReviewBPS]", dbFailOnError
' ... repeat for third and fourth tables ...
End With


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      22nd Aug 2008
That worked great Dirk, thanks. Now I just trying to get my head around how
to make into a Macro. When I use the code is shows up as a Module. I want
it to run after the append queries.

Maybe its to late and I'm not thinking straight. I'll visit again tomorrow.

Thanks Dirk
--
Eric the Rookie


"Dirk Goldgar" wrote:

> "Eric" <(E-Mail Removed)> wrote in message
> news:309B8AEE-E5FD-4A3B-9CE9-(E-Mail Removed)...
> >I run append queries from a 4 temporary tables to 4 permanent tables.
> >After
> > the append, I'd like to run a Delete Query after the append queries, that
> > will delete all records in all 4 temporary tables.
> >
> > I've looked at some ideas and code from others, but I'm not needing any
> > fault attributes. I am sure of the append functions and am sure I want
> > the
> > records deleted.
> >
> > Here is some code I am trying with only two tables, but I get an error
> > "you
> > can not delete from the specified tables"
> >
> > DELETE [1ReviewHDR].*, [2ReviewBPS].*
> > FROM 2ReviewBPS, 1ReviewHDR;

>
>
> You can only delete from one table at a time. You'll have to run 4 delete
> queries; e.g.,
>
> With CurrentDb
> .Execute "DELETE FROM [1ReviewHDR]", dbFailOnError
> .Execute "DELETE FROM [2ReviewBPS]", dbFailOnError
> ' ... repeat for third and fourth tables ...
> End With
>
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>

 
Reply With Quote
 
Stephen Lynch
Guest
Posts: n/a
 
      23rd Aug 2008
Eric:

Why do you want to put it in a macro. Just drop your code in the onclick
event of a button or whatever you are trying to do. Once you comment your
code you will not want to use macros. I started with macros and now have no
macros. Chasing down problems in a series of queries and macros is a
nightmare.

You can also use the following to get started with code:

Open the query editor, setup up your query like you normally do. Save it and
then hit the SQL code button, the one in the same as design mode. Copy the
sql code and drop it in your code with the docmd.runsql command, so you have
something like this:

' Append the data
Docmd.RunSQL "INSERT INTO tblTable1 ( Field1 ) SELECT tblTable2.Field2 FROM
tblTable2;
'Delete the tables after append
docmd.runsql "DELETE * FROM TABLE1
docmd.runsql "DELETE * FROM TABLE2
docmd.runsql "DELETE * FROM TABLE3
docmd.runsql "DELETE * FROM TABLE4

It is really a piece of cake, after a few days of struggling.

HTH

Steve





"Eric" <(E-Mail Removed)> wrote in message
news:16CC888A-DCAE-4679-BB1B-(E-Mail Removed)...
> That worked great Dirk, thanks. Now I just trying to get my head around
> how
> to make into a Macro. When I use the code is shows up as a Module. I
> want
> it to run after the append queries.
>
> Maybe its to late and I'm not thinking straight. I'll visit again
> tomorrow.
>
> Thanks Dirk
> --
> Eric the Rookie
>
>
> "Dirk Goldgar" wrote:
>
>> "Eric" <(E-Mail Removed)> wrote in message
>> news:309B8AEE-E5FD-4A3B-9CE9-(E-Mail Removed)...
>> >I run append queries from a 4 temporary tables to 4 permanent tables.
>> >After
>> > the append, I'd like to run a Delete Query after the append queries,
>> > that
>> > will delete all records in all 4 temporary tables.
>> >
>> > I've looked at some ideas and code from others, but I'm not needing any
>> > fault attributes. I am sure of the append functions and am sure I want
>> > the
>> > records deleted.
>> >
>> > Here is some code I am trying with only two tables, but I get an error
>> > "you
>> > can not delete from the specified tables"
>> >
>> > DELETE [1ReviewHDR].*, [2ReviewBPS].*
>> > FROM 2ReviewBPS, 1ReviewHDR;

>>
>>
>> You can only delete from one table at a time. You'll have to run 4
>> delete
>> queries; e.g.,
>>
>> With CurrentDb
>> .Execute "DELETE FROM [1ReviewHDR]", dbFailOnError
>> .Execute "DELETE FROM [2ReviewBPS]", dbFailOnError
>> ' ... repeat for third and fourth tables ...
>> End With
>>
>>
>> --
>> Dirk Goldgar, MS Access MVP
>> www.datagnostics.com
>>
>> (please reply to the newsgroup)
>>



 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      23rd Aug 2008
Thats great advice Steve thanks much. I have been developing Access
databases for years, and am just now getting started useing VB Script. What
a huge difference it is making and I'm hooked. Stuggling a little here and
there, but I sure like it.

Thanks again.


--
Eric the Rookie


"Stephen Lynch" wrote:

> Eric:
>
> Why do you want to put it in a macro. Just drop your code in the onclick
> event of a button or whatever you are trying to do. Once you comment your
> code you will not want to use macros. I started with macros and now have no
> macros. Chasing down problems in a series of queries and macros is a
> nightmare.
>
> You can also use the following to get started with code:
>
> Open the query editor, setup up your query like you normally do. Save it and
> then hit the SQL code button, the one in the same as design mode. Copy the
> sql code and drop it in your code with the docmd.runsql command, so you have
> something like this:
>
> ' Append the data
> Docmd.RunSQL "INSERT INTO tblTable1 ( Field1 ) SELECT tblTable2.Field2 FROM
> tblTable2;
> 'Delete the tables after append
> docmd.runsql "DELETE * FROM TABLE1
> docmd.runsql "DELETE * FROM TABLE2
> docmd.runsql "DELETE * FROM TABLE3
> docmd.runsql "DELETE * FROM TABLE4
>
> It is really a piece of cake, after a few days of struggling.
>
> HTH
>
> Steve
>
>
>
>
>
> "Eric" <(E-Mail Removed)> wrote in message
> news:16CC888A-DCAE-4679-BB1B-(E-Mail Removed)...
> > That worked great Dirk, thanks. Now I just trying to get my head around
> > how
> > to make into a Macro. When I use the code is shows up as a Module. I
> > want
> > it to run after the append queries.
> >
> > Maybe its to late and I'm not thinking straight. I'll visit again
> > tomorrow.
> >
> > Thanks Dirk
> > --
> > Eric the Rookie
> >
> >
> > "Dirk Goldgar" wrote:
> >
> >> "Eric" <(E-Mail Removed)> wrote in message
> >> news:309B8AEE-E5FD-4A3B-9CE9-(E-Mail Removed)...
> >> >I run append queries from a 4 temporary tables to 4 permanent tables.
> >> >After
> >> > the append, I'd like to run a Delete Query after the append queries,
> >> > that
> >> > will delete all records in all 4 temporary tables.
> >> >
> >> > I've looked at some ideas and code from others, but I'm not needing any
> >> > fault attributes. I am sure of the append functions and am sure I want
> >> > the
> >> > records deleted.
> >> >
> >> > Here is some code I am trying with only two tables, but I get an error
> >> > "you
> >> > can not delete from the specified tables"
> >> >
> >> > DELETE [1ReviewHDR].*, [2ReviewBPS].*
> >> > FROM 2ReviewBPS, 1ReviewHDR;
> >>
> >>
> >> You can only delete from one table at a time. You'll have to run 4
> >> delete
> >> queries; e.g.,
> >>
> >> With CurrentDb
> >> .Execute "DELETE FROM [1ReviewHDR]", dbFailOnError
> >> .Execute "DELETE FROM [2ReviewBPS]", dbFailOnError
> >> ' ... repeat for third and fourth tables ...
> >> End With
> >>
> >>
> >> --
> >> Dirk Goldgar, MS Access MVP
> >> www.datagnostics.com
> >>
> >> (please reply to the newsgroup)
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete records when certain records have duplicate column data JVroom Microsoft Excel New Users 0 26th Jan 2009 05:07 PM
Delete subform records without deleting main form records =?Utf-8?B?QW5pdGE=?= Microsoft Access Form Coding 0 21st Nov 2006 07:00 AM
how do you delete records or update records in a link table. =?Utf-8?B?SGVscG1l?= Microsoft Access Queries 2 18th Aug 2005 05:12 PM
Search for Existing Records and Delete Matching Records =?Utf-8?B?Qm9iIE11bGxlbg==?= Microsoft Access Form Coding 2 1st Jan 2005 12:17 AM
How to delete records from the original table while randomly selecting the records CaribSoft Microsoft Access Queries 2 5th Feb 2004 09:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:55 PM.