How do I close form if not used?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    How do I close form if not used?

    I want to open a form, let's call it fSelect, with some optional choices on it. If the operator makes a choice, that choice is saved to a control on the main form, and fSelect is closed.

    However, I would like to close fSelect if the operator ignores it and continues to work on the main form.

    fSelect cannot be Dialog, i.e. modal, or operator cannot ignore it.
    LostFocus for fSelect doesn't seem to fire.
    Deactivate fires, but attempts to close the form gets:
    Code:
       Run-time error '2585'
       This action can't be carried out while processing a form or report event.
    In other words, I can't close fSelect while processing the Deactivate event.

    How can I close this form (fSelect) if it is opened and displayed, but not used?
  • malcolmk
    New Member
    • Sep 2010
    • 79

    #2
    DoCmd.Close acForm, "formname"

    Comment

    • gnawoncents
      New Member
      • May 2010
      • 214

      #3
      Do you want it to close after a certain amount of time, or when they begin to interact with the main form, or on some other trigger?

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        malcolmk -
        Thanks, but this is what I'm doing now, with the result of Run-time error '2585' so the form doesn't close. Trapping the error hasn't worked either. I don't know what to do after it errors. Attempting again to close the form gets me into an infinite loop, or course.

        gnawoncents -
        I want to close the form ASAP (As Soon As Possible). I don't like timers because they're either too slow (long time) or they are too fast, and take action when operator is distracted.

        The form has one control (Listbox named lbxSelect). I've tried setting lbxSelect.SetFo cus and triggering the close on LostFocus. This event never fires if focus goes to the main form.

        I've tried giving the form focus with Me.SetFocus or Me!SetFocus, but this doesn't fire either, probably because there is an enabled, visible control on the form.

        Form_Deactivate fires, but then Run-time error '2585' when I try to execute the Close.

        I will trigger off of ANY event that fires and permits me to close the form.

        Comment

        • Mariostg
          Contributor
          • Sep 2010
          • 332

          #5
          I use the following function for a different purpose but maybe it could help. Maybe you could run it when your Main form gets the focus and if the proposed function returns true then close the form...
          Code:
          Function IsLoaded(ByVal strFormName As String) As Boolean
          
          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

          Comment

          • ChipR
            Recognized Expert Top Contributor
            • Jul 2008
            • 1289

            #6
            You haven't adequately described when you want the form to close. Unless there is an event that you want to trigger the closing of the form, you would use the timer to determine how long it had not been used.

            Why not let the user open the form modal if they need it?

            Comment

            • OldBirdman
              Contributor
              • Mar 2007
              • 675

              #7
              The main form's GotFocus doesn't fire when a control is clicked. What fires is the control's GotFocus. This would entail using the GotFocus event for every control on the form, and checking for IsLoaded.
              Normal navigation around the form would have this called almost continually for what was (I hoped) an infrequently used form.

              Comment

              • ChipR
                Recognized Expert Top Contributor
                • Jul 2008
                • 1289

                #8
                What's the purpose of the form? When does it open?

                Comment

                • OldBirdman
                  Contributor
                  • Mar 2007
                  • 675

                  #9
                  The form consists of a listbox lbxSelect. The rowsource is an SQL statement with OpenArgs as the WHERE condition. There is only 1 column in lbxSelect.

                  Main program is a log. Many of the textboxes have similar entries. For example, the textbox txtReason might have 'Stop Service' or 'Complaint' or 'Dispute Bill' or 'Change' or something completely unique. I want, when this box is entered (tab or mouse) to have the list of common entries displayed for selection, or if operator chooses, they may ignore completely and enter something else, like '2nd request, cancel order'.
                  I originally tried a hidden listbox which I could set to .Visible. Works fine, when Clicked or LostFocus it is rehidden. Takes too much space vertically as it cannot cross a record boundry on a Continuous Form.

                  I can do this by hiding the form instead of closing, and changing lbxSelect.RowSo urce from the main form and unhiding. I already have many hidden forms, and this seems to slow the computer when switching between applications.

                  Comment

                  • ChipR
                    Recognized Expert Top Contributor
                    • Jul 2008
                    • 1289

                    #10
                    Why not hide/close the form on exit of the textbox that caused it to open?

                    Comment

                    • OldBirdman
                      Contributor
                      • Mar 2007
                      • 675

                      #11
                      That works well on the LostFocus event, but if the next control the user wants is 'under' the fSelect but not in tab order, then they must click in some other area of the main form to close fSelect. I might as well put a Close Button on fSelect and be direct about it.

                      Comment

                      • ChipR
                        Recognized Expert Top Contributor
                        • Jul 2008
                        • 1289

                        #12
                        My combo boxes extend over subsequent records in continuous form view. Are you using Access 2007?

                        Comment

                        • OldBirdman
                          Contributor
                          • Mar 2007
                          • 675

                          #13
                          I use Access 2003. I tried 2007 and didn't like. This is a listbox, not combobox, so not 'dropdown', which has different rules. I didn't use combobox as I didn't want entry in the text portion.
                          I had originally thought to use cascading comboboxes (2 levels) but this doesn't work on continuous forms for the same reasons that unbound controls (i.e. CheckBoxes) don't work. The value of combo1 of the current record applies to the RowSource for all combo2.

                          Comment

                          • ChipR
                            Recognized Expert Top Contributor
                            • Jul 2008
                            • 1289

                            #14
                            So different records require different lists of options in the same field? Otherwise you could use a combo box on the main form, instead of a text box. You can even call combobox.DropDo wn on enter to display your list when they tab into the field. The user can then click an item on the list or use autocomplete.
                            Last edited by ChipR; Sep 22 '10, 09:09 PM. Reason: replace "form" with "field"

                            Comment

                            • OldBirdman
                              Contributor
                              • Mar 2007
                              • 675

                              #15
                              Yeah

                              Think States and Counties in the USA. Select state and the county list changes. Occasionally user might want to refer to something else, like 'All Counties' or in the case of Alaska, 'Not in a County'. Alaska calls them buroughs, but same logic.
                              So I need to use the field for standard as well as non-standard notations.
                              But this approach seems not to work well. Guess I'll just hide the form for now. Thanks for all the suggestions.

                              Comment

                              Working...