Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't call procedure on Report... Working on detecting out of date objects for auto update

Status
Not open for further replies.

lameid

Programmer
Jan 31, 2001
4,212
US
My general thinking is to add procedures to all my module / class module objects (forms and reports) so that return the version... That way I can check each object's version and then check to see if it is the latest copy. Long story short we end up with a customized front end and backend from a base code... some of it has business rules in it that need centrally managed...

If I add code to a module... I can call it all is well...
Code:
Option Compare Database
Option Explicit

Const conmdlExampleversion As Long = 1

Public Sub mdlBrandVersion(Optional ByRef lngReturn As Variant = 0)
  lngReturn = conmdlExampleversion
End Sub

If I add code to a report, I can't seem to call it even if I have the object open... I know I should be able to do this but I am at a loss... I've tried converting to a function just to see if it would work and nothing... I've tried a direct call like when I had it as a function...
debug.print Reports!RptWidget.rptWidgetVersion()


Code:
Option Compare Database
Option Explicit

Const conRptWidgetversion As Long = 1

Public Sub RptWidgetVersion(Optional ByRef lngReturn As Variant = 0)
  lngReturn = conRptWidgetversion
End Sub


Ultimately I am trying to use something like the below. I will loop over known object names to check versions with this. This actually works for Modules... may need another version for reports. But I am at a loss as to calling the report call.

Code:
Public Function fnModuleVersion(ModuleName As String) As Long
  Dim strCallName As String
  
  strCallName = ModuleName & "Version"
  Application.Run strCallName, fnModuleVersion 'fnModuleVersion is this function variable passed as a byRef Arg to be returned as the function return

Exit Function

fnModuleVersion_err:
  Select Case Err.Number
    Case 2517 '<Project Name> cannot find the procedure <ModuleName & "Version">
      If ModuleExists(ModuleName) Then 'This User defined function works... Likely need a version of this for Reports
        fnModuleVersion = -1 'Module Exists standard procedure does not... Likely a different animal
      Else
        fnModuleVersion = -2 'Module does not even exist in project... Likely don't need it?
      End If
    Case Else
      MsgBox "Unhandled Error in fnModuleVersion" & vbCrLf & "Error " & Err.Number & ": " & Err.Description, vbCritical
  End Select
End Function

 
So way down there in the Google results.... And I mean way down there...



My way should work according to thread but using the class module name with the object type prefix worked in my case for immediate window syntax...

Code:
Report_RptWidget.RptWidgetVersion  'Not the class name is "Report_" Followed by the Report Name.  
                                   'Class name also visible in the title bar of the Visual Basic editor when the report class is open
                                   'Calling an unopened report this way apparently instantiates the class hidden 
                                      'and out side of the typical collection (Reports) and will remain open until a regular instance is opened and closed.
                                      'Caveat: This special hidden instance fires open and load events when instantiated and unload and close when closed....
 
So then the next logical step...

Does not work... The procedure does not exist which I expected per another one of my threads or so I thought... I can't find it now.

Code:
Public Function fnReportVersion(ReportName As String) As Long
  Dim strCallName As String
  
  strCallName = "Report_" & ReportName & "." & ReportName & "Version"
  Application.Run strCallName, fnReportVersion 'fnModuleVersion is this function variable passed as a byRef Arg to be returned as the function return

Exit Function

End Function
 
Assuming the report will run a property would work... My catch 22 is that the recordsource is created by other code on data that may not be present.
Still looking for a good option.

Code:
Public Function fnReportVersion(ReportName As String) As Long
  Dim rpt As Report
  
  DoCmd.OpenReport ReportName, acViewNormal
  fnReportVersion = Reports(ReportName).Version

End Function


Code:
'Property on the Report
Public Property Get Version() As Long
  Version = conrpt_CoverFaxVersion
End Property
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top