Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Feb 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Close (A2000 W98)

    I have a form which is used in two different area's of my db.
    I am trying to make the following code work:

    Private Sub Form_Close()
    On Error GoTo Errtrap
    Forms!FRMDETAILS.SetFocus
    Forms!FRMDETAILS.Refresh
    Forms!FRMDETAILS!cmbClientCode.SetFocus

    Forms!mnuWorkShopManager.Visible = True
    Forms!mnuWorkShopManager.SetFocus
    Forms!mnuWorkShopManager!cmbMaintenance.SetFocus
    Forms!mnuWorkShopManager!cmbMaintenance.Dropdown

    Exit Sub
    Errtrap:
    End Sub

    I need the form to close and recognise which of the two forms is loaded.

    frmDetails or mnuWorkshopManager.

    from this return the focus to whichever form is loaded.

    Can this be done.

    Dave

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Create this function
    <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 As Long = 0
    Const conDesignView As Long = 0

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

    End Function</pre>

    And modify your code to :
    <pre>Private Sub Form_Close()
    On Error GoTo Errtrap
    If IsLoaded("FRMDEATILS") Then
    Forms!FRMDETAILS.SetFocus
    Forms!FRMDETAILS.Refresh
    Forms!FRMDETAILS!cmbClientCode.SetFocus
    End If
    If IsLoaded("mnuWorkShopManager") Then
    Forms!mnuWorkShopManager.Visible = True
    Forms!mnuWorkShopManager.SetFocus
    Forms!mnuWorkShopManager!cmbMaintenance.SetFocus
    Forms!mnuWorkShopManager!cmbMaintenance.Dropdown
    End If
    Exit Sub
    Errtrap:
    End Sub</pre>

    Francois

  3. #3
    Star Lounger
    Join Date
    Feb 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Francois

    What do I do with the isLoaded function.

    Thanks

    Dave

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Open a module, and copy the function in it.
    Save the module with any name you want but not IsLoaded.
    Now it's available to use with the modified code in the On Close Event.
    Francois

  5. #5
    Star Lounger
    Join Date
    Feb 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Francois.

    I'm getting Ambiguous name (isLoaded) error.

    What does this mean.

    Dave

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Do you have saved your Module with the name "IsLoaded" , if yes , rename it to anything else.
    If not then you have copy the code twice, maybe once in the module, and once in the form code. Remove it from the form code.
    Francois

  7. #7
    Star Lounger
    Join Date
    Feb 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Francois

    it looks like I have another function called IsLoaded in my db

    is it possible to change one of them to lets say:
    ..............

    Sorry Francois, I only got your recent post after I sent the latest one.

    I have Named the module "See Which Form"

    Their is another section of code within the db with the same name.


    If I change the recent one to "IsLoaded1" and the references to it.

    Will this be OK

    Dave

    Isloaded1 or something

    Dave

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Change the to line in the function as follow
    <pre>Function IsFormLoaded(ByVal strFormName As String) As Boolean
    ' Returns True if the specified form is open in Form view or Datasheet view.
    Const conObjStateClosed As Long = 0
    Const conDesignView As Long = 0
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
    If Forms(strFormName).CurrentView <> conDesignView Then
    IsFormLoaded = True
    End If
    End If
    End Function</pre>

    In the On close event, rename IsLoaded with IsFormLoaded in the two If lines
    Francois

  9. #9
    Star Lounger
    Join Date
    Feb 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Close (A2000 W98)

    Thanks for the help.

    Its all ok now

    Dave

Posting Permissions

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