_.CurrentView

doco

Power User
Local time
Today, 15:31
Joined
Feb 14, 2007
Messages
482
Just a thought...

I am making the attempt to revamp the ubiquitous IsLoaded() function to include reports. But have found
Code:
    ...
 
    Reports(szName).CurrentView = Constant     '    0/-1
    ....

Produces an error. So resorted to using
Code:
Function IsLoaded(ByVal szName As String, _
         Optional ByVal szType As String = "Input") As Boolean
 '  Returns True if the specified form is open
 '  in Form view or Datasheet view.
 
    Const conObjStateClosed = 0
    Const conDesignView = 0
    Dim lType As Long
 
    lType = acForm
    If UCase(szType) <> "INPUT" Then
        lType = acReport
    End If
    If SysCmd(acSysCmdGetObjectState, lType, szName) <> conObjStateClosed Then
        Select Case UCase(szType)
            Case "INPUT"
                If Forms(szName).CurrentView <> conDesignView Then
                    IsLoaded = True
                End If
            Case Else
                If Reports(szName).Visible Then
                    IsLoaded = True
                End If
        End Select
    End If
 
End Function

It works but its kind of like being in the woods with a nature call and no paper: Flannel Mullen or moss will work but... :rolleyes::(

Thoughts?
 
Erm, I wouldn't use "IsLoaded" as that is a built-in function to test if any AccessObject is loaded:

Code:
If Not CurrentProject.AllForms("NameOfForm").IsLoaded Then
   Docmd.Open acForm "NameOfForm" , , , acDesignView
End If
 
Pretty good stuff at a glance... Just brainstorming a little...I'd be tempted to build a separate function for forms and reports rather than packing dual functionality into one procedure, which increases complexity, which typically makes maintenance more difficult than otherwise...

Code:
Function FormLoaded(FormName as Form) As Boolean

Function ReportLoaded(ReportName as Report) as Boolean

Else change the optional parameter's default value from input to form and/or create an enumerator -- so the caller can choose from a list -- for the second parameter (assiming you can do this in Access)...

Your call, of course...

Regards,
Tim
 
For my own reasons I prefer to have a single function to perform the dual purpose but having the naming convention be more intuitive is good. Also I did create a module (MVars) with a Public Enum that was a trick idea. I am still wondering why the form object has a _CurrentView property and the report doesn't. Anyway here are the changes
Code:
Public Function FormReportIsLoaded(ByVal szName As String, _
                          Optional ByVal dcFlag As FormReportFlag = dcForm) As Boolean
    
    Dim fTemp As Boolean
    Const OBJSTATECLOSED As Byte = 0
    Const DESIGNVIEW As Byte = 0
    
    fTemp = False
    
    If SysCmd(acSysCmdGetObjectState, dcFlag, szName) <> OBJSTATECLOSED Then
        Select Case dcFlag
            Case acForm
                If Forms(szName).CurrentView = DESIGNVIEW Then
                    fTemp = True
                End If
            Case Else
                If Reports(szName).Visible Then
                    fTemp = True
                End If
        End Select
    End If
    FormReportIsLoaded = fTemp
End Function
 
Public Enum FormReportFlag
    dcForm = acForm
    dcReport = acReport
End Enum

Works good.
 
FWIW, I had a similar problem and decided that I'd make two functions that accepts a specific data type, then both calling one single function with an extra parameter indicating what data type it is, so I don't have to always pass two parameter, just select one function, and let it supply the extra information about datatype.

Also, I think you could just use AccessObject instead of Form/Report which supports both currentview and type property...
 

Users who are viewing this thread

Back
Top Bottom