Function ChangeRemoteReport(DbPath As String, _
ReportName As String, _
ControlName As String, _
PropertyName As String, _
NewValue As Variant) _
As Long
' Purpose: Changes any property of any control on any report in any external database
' (assuming the property is read/write).
' Returns: 0 if successful, else runtime error number
Dim appAccess As Access.Application
Dim rpt As Report
On Error GoTo ErrorHandler
'If Len(Dir(DbPath)) > 0 Then
Set appAccess = New Access.Application
With appAccess
.Echo False
.OpenCurrentDatabase DbPath
.DoCmd.OpenReport ReportName, acDesign
Set rpt = .Reports(ReportName)
rpt.Controls(ControlName).Properties(PropertyName) = NewValue
Set rpt = Nothing
.DoCmd.Save
.DoCmd.Close acReport, ReportName
End With
ChangeRemoteReport = 0
'End If
ErrorExit:
On Error Resume Next
appAccess.Quit
Set appAccess = Nothing
Exit Function
ErrorHandler:
ChangeRemoteReport = Err.Number
Select Case Err.Number
Case 7866: ' Database not found or is already exclusively opened
MsgBox "The database you specified," & vbCrLf _
& "'" & DbPath & "'," & vbCrLf _
& "was not found or is currently open in exclusive mode.", _
vbExclamation, "Could not open database"
Case 2103: ' Report doesn't exist
MsgBox "The report '" & ReportName & "' doesn't exist in the database " _
& vbCrLf & "'" & DbPath & "'", _
vbExclamation, "Report not found"
Case 2465: ' Can't find the control
MsgBox "The control '" & ControlName & "' doesn't exist in the report '" _
& ReportName & "'", _
vbExclamation, "Control not found"
Case 2455: ' Invalid reference to property
MsgBox "The control '" & ControlName & "' doesn't have a '" _
& PropertyName & "' property", _
vbExclamation, "Property not found"
Case 2113: ' Invalid property value
MsgBox "The value '" & NewValue & "' is not valid for the '" _
& PropertyName & "' property", _
vbExclamation, "Invalid property setting"
Case Else:
MsgBox "Error " & Err.Number & ":" & vbCrLf & Err.Description, _
vbCritical + vbOKOnly, "Runtime error"
End Select
Resume ErrorExit
End Function