Retrieve the Description property for All the MS Access Reports using VBA Code

Is it possible to loop through all the reports in the current database and retrieve the description for each report.  This is what I have so far:

Private Sub Command0_Click()
Dim obj As AccessObject, dbs As Object
Dim rpt As Report
Dim P As Property
Set dbs = Application.CurrentProject
For Each obj In dbs.AllReports
    Debug.Print obj.Property & vbCrLf
End Sub

Any help would be appreciated.
Who is Participating?
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
You must get a handle on the Document for that object ... the code below does this for you. Copy/paste it into a Standard Module, then call it like this:

Dim sReportDescription As String

sReportDescription = GetDescription("YourReportName",acReport)

To use this in a Loop, just replace your Debug.Print with this:

GetDescription(obj.Name, acReport)

Function GetDescription(ObjectName As String, ObjectType As AcObjectType) As String
'/Created: 11/13/2008 07:13 AM
'/Created By: Scott
Dim doc As DAO.Document
Dim dbs As DAO.Database
Dim con As DAO.Container
On Error GoTo Err_GetDescription
Set dbs = CurrentDb
Set con = dbs.Containers(ObjectType)
Set doc = con.Documents(ObjectName)
GetDescription = doc.Properties("Description").Value
  On Error Resume Next
  Set doc = Nothing
  Set dbs = Nothing
  Set con = Nothing
  Exit Function
  Select Case Err
    Case 3270 '/property not found
      GetDescription = ""
    Case Else
     MsgBox "An error occurred in this application." & vbCrLf & vbCrLf & Err & ":" & Error$ & vbCrLf & vbCrLf & "Technical Information: Occurred in [Module1].[GetDescription]", vbCritical, "Application Error"
  End Select
  Resume Exit_GetDescription
End Function

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.