MikeC said:
Can anyone tell me whether there is a way in VBA to
identify all reports in my database having a tag property
equal to some value? For instance, if the tag property
is "Shared", then I would like to capture the name of the
report in a string variable...preferably without having to
open each report.
Properties that you can set when the object is open (such as
Tag) can only be read when the object is open (usually
either design view or form/report view).
However, you can create user defined properties on the
form/report Document. These properties can be tested
without opening the object.
The following procedure can be used to create/set a user
defined property for a report document.
Public Sub SetReportDocProp(strDocName As String, _
strPropName As String, varPropValue As Variant)
Dim db As Database
Dim doc As Document
Dim prp As Property
Set db = CurrentDb()
Set doc = db.Containers("Reports").Documents(strDocName)
On Error GoTo ErrorHandler
doc.Properties(strPropName) = varPropValue
ExitHere:
Set doc = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
Select Case Err.number
Case 3270
Set prp = doc.CreateProperty(strPropName, _
dbText, varPropValue)
doc.Properties.Append prp
doc.Properties.Refresh
Case Else
MsgBox Err.number & " - " & Err.Description
End Select
Resume ExitHere
End Sub
The property value can be tested in a loop to determine the
reports that have the property set:
Public Sub ListReportsInGroup(strPropName As String,
varPropValue As Variant)
Dim db As Database
Dim doc As Document
On Error GoTo ErrorHandler
Set db = CurrentDb()
For Each doc In db.Containers("Reports").Documents
If doc.Properties(strPropName) = varPropValue Then
Debug.Print doc.Name
End If
SkipIt:
Next doc
ExitHere:
Set db = Nothing
Exit Sub
ErrorHandler:
Select Case Err.number
Case 3270
Resume SkipIt
Case Else
MsgBox Err.number & " - " & Err.Description
End Select
Resume ExitHere
End Sub