If you want to find whether a particular report exists or not in a access database. and if found then delete the report.
Here is the code-
Sub check_if_report_exists_and_delete_the_report()
Dim rptname As String
Dim rpt As Object
Dim found As Boolean
rptname = "Copy Of rep_name_a"
found = False
For Each rpt In Application.CurrentProject.AllReports
If rpt.Name = rptname Then
found = True
Exit For
End If
Next
If found = True Then
On Error Resume Next
DoCmd.Close acReport, rptname, acSaveYes
DoCmd.DeleteObject acReport, rptname
MsgBox "Report found & Deleted", vbInformation
Else
MsgBox "Report Not Found", vbInformation
End If
End Sub
No comments:
Post a Comment