Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Frederick, Maryland, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Opening a Form (A2K SR-1)

    On my main data entry form, there is a Company field that is populated by a dropdown box tied to the Company table. Currently, if a user starts to enter a new record and discovers that that particular company is not already in the Company table, he/she must exit the main data entry form and go to the Company form to enter the new company. When he/she is done entering the new company, they press the Main Menu button on the Company form to return to the switchboard system.

    I would like the user to be able to double-click on the Company field in the main data entry form to bring up the Company form without having to exit the main data entry form. That's easy. But currently, when the user presses the Main Menu button on the Company form, they are returned to the switchboard system and NOT the main data entry form. So I need to program the Main Menu button on the Company form to check if the main data entry form is open and, if so, return to it instead of the switchboard system and, if not, return to the switchboard system.

    How do I test for an open form? I envision my Company form Main Menu button code looking something like this, but I don't know exactly how to check for an open form:

    If IsOpen(Main Data Entry Form) = True Then
    DoCmd.Close 'this will close the Company form and return user to main data entry form
    Else
    DoCmd.Close 'this will close the Company form
    stDocName = "frmSWITCHBOARD"
    DoCmd.OpenForm stDocName 'this will open the main switchboard form if the user is not in the main data entry form
    End If

    Am I close? Thanks for the help and sorry for the confusing message.

  2. #2
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Form (A2K SR-1)

    Taken from Northwind
    <pre>Function IsLoaded(ByVal strFormName As String) As Boolean
    ' Returns True if the specified form is open in Form view or Datasheet view.

    Const conObjStateClosed = 0
    Const conDesignView = 0

    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
    If Forms(strFormName).CurrentView <> conDesignView Then
    IsLoaded = True
    End If
    End If

    End Function
    </pre>




    HTH
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  3. #3
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Frederick, Maryland, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Form (A2K SR-1)

    I can't get this to work. I know it's a code problem:

    Function IsLoaded(ByVal frmSUBINFO As String) As Boolean
    Const conObjStateClosed = 0
    Const conDesignView = 0

    If SysCmd(acSysCmdGetObjectState, acForm, frmSUBINFO) <> conObjStateClosed Then
    DoCmd.Close 'will close Company form to return to already open main data entry form (frmSUBINFO)
    Else
    DoCmd.Close 'will close Company form to return to switchboard
    DoCmd.OpenForm "frmSWITCHBOARD"
    End If

    Exit_ExitAccess_Click:
    Exit Function

    Err_ExitAccess_Click:
    MsgBox Err.Description
    Resume Exit_ExitAccess_Click

    End Function

  4. #4
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Form (A2K SR-1)

    Sorry I didn't make myself very clear...

    If IsLoaded(Main Data Entry Form) = True Then
    DoCmd.Close 'this will close the Company form and return user to main data entry form
    Else
    DoCmd.Close 'this will close the Company form
    stDocName = "frmSWITCHBOARD"
    DoCmd.OpenForm stDocName 'this will open the main switchboard form if the user is not in the main data entry form
    End If


    should work

    Paste the IsLoaded function into a Standard Module (I use a module called basUsefulStuff). You can then just put basUsefulStuff into a new project and have all the 'UsefulStuff' to hand.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  5. #5
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Frederick, Maryland, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Form (A2K SR-1)

    Steve,

    Thank you, it worked perfectly. I'm new to the module concept, but I'm beginning to like it already! Thanks again.

Posting Permissions

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