Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5

    Unanswered: Passing a report name to currentproject.AllForms

    I am in a bit of a disagreement with a coworker on the accuracy and functionality of the following code. I say iit will never show isloaded as true if a reportname is passed as strFrmName instaed of a form name.

    Who is right?



    Set oAccessObject = CurrentProject.AllForms(strFrmName)
    If oAccessObject.IsLoaded Then
    If oAccessObject.CurrentView <> 0 Then '0 represents Design View
    IsLoaded = True
    End If
    End If
    Dale Houston, TX

  2. #2
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by axsprog View Post
    I am in a bit of a disagreement with a coworker on the accuracy and functionality of the following code. I say iit will never show isloaded as true if a reportname is passed as strFrmName instaed of a form name.

    Who is right?

    Set oAccessObject = CurrentProject.AllForms(strFrmName)
    If oAccessObject.IsLoaded Then
    If oAccessObject.CurrentView <> 0 Then '0 represents Design View
    IsLoaded = True
    End If
    End If
    This code is commonly used:

    Code:
    Function IsLoaded(ByVal strFormName As String) As Boolean
     ' Returns True if the specified form is open in Form view or Datasheet view.
        Dim oAccessObject As AccessObject
    
        Set oAccessObject = CurrentProject.AllForms(strFormName)
        If oAccessObject.IsLoaded Then
            If oAccessObject.CurrentView <> acCurViewDesign Then
                IsLoaded = True
            End If
        End If
        
    End Function
    I just tested it in 2010:

    Form not opened:

    Code:
    ? IsLoaded("frmSelectOrdersToPrint")
    False
    Form opened in design view
    Code:
    ? IsLoaded("frmSelectOrdersToPrint")
    False
    form opened in Form View
    Code:
    ? IsLoaded("frmSelectOrdersToPrint")
    True

    form opened in Datasheet View
    Code:
    ? IsLoaded("frmSelectOrdersToPrint")
    True
    Note: The above will Work with Access 2000 and later


    form opened in Layout View (Access 2007/2010)
    Code:
    ? IsLoaded("frmSelectOrdersToPrint")
    True
    I have been using this code for over 10 years with great success.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •