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/