Loop Problem

B

bodhisatvaofboogie

Alright, This formula is working, though it is not successfully looping
through all the reports. It ends up erroring out.
I want it to loop through each of the reports within the database and delete
it if there is a 1 at the end of the label of the report. Like I said it
works, however the loop is incorrect, any ideas? THANKS!!!

Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
For Each obj In dbs.AllReports
If Right(obj.Name, 1) = "1" Then
DoCmd.DeleteObject acReport, obj.Name
End If
Next obj
 
J

Jason Lepack

It works fine for me. Some information about the error would be
helpful.

Cheers,
Jason Lepack
 
J

John W. Vinson

Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
For Each obj In dbs.AllReports
If Right(obj.Name, 1) = "1" Then
DoCmd.DeleteObject acReport, obj.Name
End If
Next obj

Loop backwards instead of forwards:

Dim obj As AccessObject, dbs As Object
Dim i As Integer
Set dbs = Application.CurrentProject
For i = dbs.AllReports.Count - 1 TO 0 Step -1
Set obj = dbs.AllReports(i)
If Right(obj.Name, 1) = "1" Then
DoCmd.DeleteObject acReport, obj.Name
End If
Next i


John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top