PC Review


Reply
Thread Tools Rate Thread

Deleting many forms or queries or reports

 
 
jean
Guest
Posts: n/a
 
      19th Jul 2010
Hi

I have a database containing aroud 100 form, 100 queries and 100
reports

Let say I want to delete all reports from one database an import all
reports from another database.

Right now, the only way to delete reports is one by one so I go Delete-
Entre, Delete-enter 100 times

When I want to import new records, I can go with Select all and bingo
they are imported easily.

Is there a command or something else that would delete All reports or
All Queries or All forms easily

thanks
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      19th Jul 2010
You can use VBA code to do this. HERE is some OLD code (originally written in
Access 97) that might work for you.

BACKUP your database before using this. There is no UNDO.

Public Sub sDeleteAllForms()
Dim i As Long
Dim db As DAO.Database
Dim c As DAO.Container

Set db = CurrentDb()
Set c = db.Containers("Forms")
For i = c.Documents.Count - 1 To 0 Step -1
Debug.Print c.Documents(i).Name
DoCmd.DeleteObject acForm, c.Documents(i).Name
Next i

For i = CurrentProject.AllForms.Count - 1 To 0 Step -1
DoCmd.DeleteObject acForm, CurrentProject.AllForms(i).Name
Next i

End Sub

Same code to delete all reports in a database just change the line
Set c = db.Containers("Forms")
to
Set c = db.Containers("Reports")

and change
DoCmd.DeleteObject acForm, c.Documents(i).Name
to
DoCmd.DeleteObject acReport, c.Documents(i).Name

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

jean wrote:
> Hi
>
> I have a database containing aroud 100 form, 100 queries and 100
> reports
>
> Let say I want to delete all reports from one database an import all
> reports from another database.
>
> Right now, the only way to delete reports is one by one so I go Delete-
> Entre, Delete-enter 100 times
>
> When I want to import new records, I can go with Select all and bingo
> they are imported easily.
>
> Is there a command or something else that would delete All reports or
> All Queries or All forms easily
>
> thanks

 
Reply With Quote
 
Access Developer
Guest
Posts: n/a
 
      19th Jul 2010
Get External Data will allow you to import from one to all of each kind of
object. Have you considered creating a new, empty database and importing the
objects you want from each of the two (or more) existing databases?

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access


"jean" <(E-Mail Removed)> wrote in message
news:a27aaf4e-ed76-49bd-a1bb-(E-Mail Removed)...
> Hi
>
> I have a database containing aroud 100 form, 100 queries and 100
> reports
>
> Let say I want to delete all reports from one database an import all
> reports from another database.
>
> Right now, the only way to delete reports is one by one so I go Delete-
> Entre, Delete-enter 100 times
>
> When I want to import new records, I can go with Select all and bingo
> they are imported easily.
>
> Is there a command or something else that would delete All reports or
> All Queries or All forms easily
>
> thanks



 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      20th Jul 2010
John Spencer <(E-Mail Removed)> wrote in
news:i228kb$qln$(E-Mail Removed):

> Public Sub sDeleteAllForms()
> Dim i As Long
> Dim db As DAO.Database
> Dim c As DAO.Container
>
> Set db = CurrentDb()
> Set c = db.Containers("Forms")
> For i = c.Documents.Count - 1 To 0 Step -1
> Debug.Print c.Documents(i).Name
> DoCmd.DeleteObject acForm, c.Documents(i).Name
> Next i
>
> For i = CurrentProject.AllForms.Count - 1 To 0 Step -1
> DoCmd.DeleteObject acForm, CurrentProject.AllForms(i).Name
> Next i
>
> End Sub
>
> Same code to delete all reports in a database just change the
> line
> Set c = db.Containers("Forms")
> to
> Set c = db.Containers("Reports")
>
> and change
> DoCmd.DeleteObject acForm, c.Documents(i).Name
> to
> DoCmd.DeleteObject acReport, c.Documents(i).Name


That can't be A97 code, as it uses CurrentProject.AllForms. In fact,
it seems to me you've got duplicate code, as the two counter loops
are indentical in result (the second won't have anything to do).

So, it seems to me your code would either be this:

Dim i As Long
Dim db As DAO.Database
Dim c As DAO.Container

Set db = CurrentDb()
Set c = db.Containers("Forms")
For i = c.Documents.Count - 1 To 0 Step -1
Debug.Print c.Documents(i).Name
DoCmd.DeleteObject acForm, c.Documents(i).Name
Next i
Set db = Nothing

Or it would be this:

Dim i As Long

For i = CurrentProject.AllForms.Count - 1 To 0 Step -1
DoCmd.DeleteObject acForm, CurrentProject.AllForms(i).Name
Next i

(I also have a problem using "i" as the variable name for as long
counter, but that's not really relevant here. It can be done
entirely without a counter, in fact:

Dim varItem As Variant

For Each varItem In CurrentProject.AllForms
DoCmd.DeleteObject acForm, varItem.Name
Next varItem

....while you still need the variable, you don't need to muck about
with the collection count)

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      20th Jul 2010
Interesting I just tested the variations of that code and none of them seemed
to work when deleting forms.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

David W. Fenton wrote:
> John Spencer <(E-Mail Removed)> wrote in
> news:i228kb$qln$(E-Mail Removed):
>
>> Public Sub sDeleteAllForms()
>> Dim i As Long
>> Dim db As DAO.Database
>> Dim c As DAO.Container
>>
>> Set db = CurrentDb()
>> Set c = db.Containers("Forms")
>> For i = c.Documents.Count - 1 To 0 Step -1
>> Debug.Print c.Documents(i).Name
>> DoCmd.DeleteObject acForm, c.Documents(i).Name
>> Next i
>>
>> For i = CurrentProject.AllForms.Count - 1 To 0 Step -1
>> DoCmd.DeleteObject acForm, CurrentProject.AllForms(i).Name
>> Next i
>>
>> End Sub
>>
>> Same code to delete all reports in a database just change the
>> line
>> Set c = db.Containers("Forms")
>> to
>> Set c = db.Containers("Reports")
>>
>> and change
>> DoCmd.DeleteObject acForm, c.Documents(i).Name
>> to
>> DoCmd.DeleteObject acReport, c.Documents(i).Name

>
> That can't be A97 code, as it uses CurrentProject.AllForms. In fact,
> it seems to me you've got duplicate code, as the two counter loops
> are indentical in result (the second won't have anything to do).
>
> So, it seems to me your code would either be this:
>
> Dim i As Long
> Dim db As DAO.Database
> Dim c As DAO.Container
>
> Set db = CurrentDb()
> Set c = db.Containers("Forms")
> For i = c.Documents.Count - 1 To 0 Step -1
> Debug.Print c.Documents(i).Name
> DoCmd.DeleteObject acForm, c.Documents(i).Name
> Next i
> Set db = Nothing
>
> Or it would be this:
>
> Dim i As Long
>
> For i = CurrentProject.AllForms.Count - 1 To 0 Step -1
> DoCmd.DeleteObject acForm, CurrentProject.AllForms(i).Name
> Next i
>
> (I also have a problem using "i" as the variable name for as long
> counter, but that's not really relevant here. It can be done
> entirely without a counter, in fact:
>
> Dim varItem As Variant
>
> For Each varItem In CurrentProject.AllForms
> DoCmd.DeleteObject acForm, varItem.Name
> Next varItem
>
> ...while you still need the variable, you don't need to muck about
> with the collection count)
>

 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      21st Jul 2010
John Spencer <(E-Mail Removed)> wrote in
news:i24opt$2gu$(E-Mail Removed):

> Interesting I just tested the variations of that code and none of
> them seemed to work when deleting forms.


What error did you get?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      22nd Jul 2010
In all variations of the code, I got

Error# 29068 : "Name of Database" cannot complete this operation. You must
stop the code and try again.

Access 2003
Calling routine from the VBA immediate window

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

David W. Fenton wrote:
> John Spencer <(E-Mail Removed)> wrote in
> news:i24opt$2gu$(E-Mail Removed):
>
>> Interesting I just tested the variations of that code and none of
>> them seemed to work when deleting forms.

>
> What error did you get?
>

 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      22nd Jul 2010
John Spencer <(E-Mail Removed)> wrote in
news:i29fkt$85i$(E-Mail Removed):

> In all variations of the code, I got
>
> Error# 29068 : "Name of Database" cannot complete this operation.
> You must stop the code and try again.
>
> Access 2003
> Calling routine from the VBA immediate window


Which line of code?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      22nd Jul 2010
Any of the variations that use
DoCmd.DeleteObject acForm, c.Documents(i).Name


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

David W. Fenton wrote:
> John Spencer <(E-Mail Removed)> wrote in
> news:i29fkt$85i$(E-Mail Removed):
>
>> In all variations of the code, I got
>>
>> Error# 29068 : "Name of Database" cannot complete this operation.
>> You must stop the code and try again.
>>
>> Access 2003
>> Calling routine from the VBA immediate window

>
> Which line of code?
>

 
Reply With Quote
 
David W. Fenton
Guest
Posts: n/a
 
      23rd Jul 2010
John Spencer <(E-Mail Removed)> wrote in
news:i2a7q7$m2k$(E-Mail Removed):

> Any of the variations that use
> DoCmd.DeleteObject acForm, c.Documents(i).Name


If you do Debug.Print c.Documents(i).Name (or whichever variation),
does that, too, cause the error?

If not, what about putting parens around c.Documents(i).Name, to
force evaluation (maybe there's a ByRef problem)?

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/
 
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
Forms and Queries and Reports =?Utf-8?B?TWFyYw==?= Microsoft Access Forms 3 21st Sep 2006 07:05 PM
Forms, Queries, Reports, oh my! tmoore4748 Microsoft Access 7 23rd Aug 2004 02:29 AM
Forms / Queries / Reports Jeff Microsoft Access Form Coding 3 20th Jan 2004 03:09 PM
Reports / Forms / Queries Jeff Microsoft Access Getting Started 5 20th Jan 2004 02:04 PM
Forms / Reports / Queries Jeff Microsoft Access Macros 1 20th Jan 2004 02:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:16 AM.