Loop Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
It works fine for me. Some information about the error would be
helpful.

Cheers,
Jason Lepack
 
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]
 
Back
Top