none
Why won't ComboBox dropdown stay down?

    Question

  • I have a combobox on a form with rowsource set to Value list. When the form is opened I populate the list, then execute these steps:

    dd.SetFocus
    dd.Dropdown

    The list drops down and immediately closes. How do I keep it open?

    Thanx.

     


    Darrell H Burns
    Wednesday, December 22, 2010 6:52 PM

Answers

  • Folks - I have found a solution to prevent the dropdown "flash". The following code will allow the dropdown to be filled on entering the control either by tabbing in or by clicking the dropdown arrow:

    Private Sub fldMinVal_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      DoCmd.CancelEvent '1. Cancel MouseDown to avoid dropdown "flash"
    End Sub
    
    Private Sub fldMinVal_Enter() '2. Use Enter instead of GotFocus to avoid dropdown "flash"
      FillMinMax "Min"
      fldMinVal.SetFocus '3. SetFocus manually to avoid dropdown "flash"
      If IsNull(fldMinVal) Then
        fldMinVal.Dropdown
      End If
    End Sub
    
    

     

    Thanks everybody who tried helping me out with this dilemma!

    DDD


    Darrell H Burns
    Friday, December 31, 2010 2:24 PM

All replies

  • "DarrellDoesData" wrote in message
    news:386ffba4-dd01-4e07-9e75-aa47e4b45b01@communitybridge.codeplex.com...
    >I have a combobox on a form with rowsource set to Value list. When the form
    >is opened I populate the list, then execute these steps:
    >
    > dd.SetFocus
    > dd.Dropdown
    >
    > The list drops down and immediately closes. How do I keep it open?
     
    What event is that code in?  Do you have code in the combo's GotFocus or
    Enter event?  Is there other code, following what you posted, that refers to
    the combo box and may be affecting its state?
     
     

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html
    Wednesday, December 22, 2010 7:05 PM
  • Hi Dirk.

    It's in the Form_Open event. No other event handlers on the combobox control.

    Code snippet:
        For Each File In Files
               ddDatabase.AddItem Data_Path + File.Name
        Next File

        ddDatabase.SetFocus
        ddDatabase.Value = ddDatabase.ItemData(0)
        ddDatabase.Dropdown


    Darrell H Burns
    Wednesday, December 22, 2010 7:15 PM
  • "DarrellDoesData" wrote in message
    news:c99ad56f-097d-4162-a25e-2dd761ec38a1@communitybridge.codeplex.com...
    > Hi Dirk.
    >
    > It's in the Form_Open event. No other event handlers on the combobox
    > control.
    >
    > Code snippet:
    >    For Each File In Files
    >           ddDatabase.AddItem Data_Path + File.Name
    >    Next File
    >
    >    ddDatabase.SetFocus
    >    ddDatabase.Value = ddDatabase.ItemData(0)
    >    ddDatabase.Dropdown
     
    That works fine for me in Access 2003.  What version of Access are you
    using?  At a pinch, I can test with Access 2007, but not Access 2010.
     
    Does the form have a Timer event that might be firing?
     
     

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html
    Wednesday, December 22, 2010 7:21 PM
  • Access 2007. No timer. It happens on other forms, too, when I trigger the dropdown in the OnEnter event.
    Darrell H Burns
    Wednesday, December 22, 2010 8:23 PM
  • Hi Darrell
     
    This happens because the form is requeried or because the control looses the focus.
    What happens after the code you posted. What are you doing later, setting filters for example forces the form to requery it's data and redisplay itself which makes the dropdown loosing it's focus.
     
    If you can't change this behaviour in the Form_Open event you should place this code in the Form_Current Event. This one is fired whenever the data is requeried.
     
    Henry
     
    Access 2007. No timer. It happens on other forms, too, when I trigger the dropdown in the OnEnter event.
    Darrell H Burns
    • Marked as answer by Bruce Song Monday, December 27, 2010 12:48 PM
    • Unmarked as answer by Bruce Song Tuesday, December 28, 2010 1:55 AM
    Thursday, December 23, 2010 3:54 AM
  • It's happening immediately...at the point where I execute ddDatabase.Dropdown it expands and then immediately closes back up. The next statement following is an Exit Sub. When I step thru in debug mode (F8) the form doesn't display until after the procedure is completed so I can't see the dropdown happening.
    Darrell H Burns
    Friday, December 24, 2010 11:21 AM
  • Hi Darrell
    Try to place this code into the Form_Current event. It should work there.
    Henry
    It's happening immediately...at the point where I execute ddDatabase.Dropdown it expands and then immediately closes back up. The next statement following is an Exit Sub. When I step thru in debug mode (F8) the form doesn't display until after the procedure is completed so I can't see the dropdown happening.
    Darrell H Burns
    Monday, December 27, 2010 10:00 AM
  • Hi Henry,

    I tested that the code also does not work well in Form_Current event. However, when I put it in Detail_Paint event such like:

    Private Sub Detail_Paint()
        ddDatabase.Value = ddDatabase.ItemData(0)
        ddDatabase.SetFocus
        ddDatabase.Dropdown
    End Sub

    It works well, and I can see the the ComboBox in DropDown state. Based on my analysis, I think when opening the form, the following events occur in this order:

    Fom_Open → Fom_Load → Fom_Resize → Fom_Activate → Fom_Current → Detail_Paint

    And Darrenll, if you put the code in Open event, it will lose the focus and you can't see the Combo Box in Dropdown state finally.

    I hope it can help you and feel free to follow up.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Bruce Song Monday, December 27, 2010 12:48 PM
    • Unproposed as answer by Bruce Song Tuesday, December 28, 2010 1:55 AM
    Monday, December 27, 2010 12:47 PM
  • Hi Bruce.

    I'm not following you...I don't see an event called "Detail_Paint".

    Form_open isn't the only place I experience this problem. It also happens in the following case where FillMinMax fills the combobox value list with AddItems, and I conclude with the dropdown...

    Private Sub fldMinVal_GotFocus()
      FillMinMax "Min"
      fldMinVal.Dropdown
    End Sub
    

    ...but only when the user clicks on the dropdown. It stays open if tabbed into.

    Any ideas?

    Thanx!


    Darrell H Burns
    Monday, December 27, 2010 4:05 PM
  • Sorry, Henry, but I don't see any code.

    I don't want to use Form_Current because this is a data entry form and there are many other events that trigger it besides a Form_Open. As a matter of practice, I never use the Form_Current event because of such unintended consequences.

    DDD


    Darrell H Burns
    Monday, December 27, 2010 4:11 PM
  • Darrell,

    It's on the form's property. Right click on the form's Detail bar to open the Properties Sheet(if it's not opened). Go to the Event tab - scroll down to "On Paint" event. Select "[event procedure]".

    I'm not sure it avialable in 2007 but it's avialable in 2010.

    Tuesday, December 28, 2010 9:40 AM
  • Yes the event is available in 2007, and the code works -- but -

    The paint event does not occur ONLY when the form is opened, so the code should be changed to something like:

    Private Sub Detail_Paint()
    Static binDropped AS Boolean
        If binDropped Then
           Exit Sub
       End If
        ddDatabase.Value = ddDatabase.ItemData(0)
        ddDatabase.SetFocus
        ddDatabase.Dropdown
        binDropped = True
    End Sub

    Tuesday, December 28, 2010 1:36 PM
  • I have Access 2007 and my Form control does not have an OnPaint event. The form HEADER and form FOOTER controls have it, but not the Form itself.

    Where would I call the proc "Private Sub Detail_Paint()"?

    Also, how would this help in the case where I invoke the dropdown from a GotFocus? As I mentioned earlier, I get the same dropdown "flash" behavior when the user hits the dropdown arrow and triggers the following  code, but the flash doesn't happen when the field is entered by tabbing...

    Private Sub fldMinVal_GotFocus()
     FillMinMax "Min"
     fldMinVal.Dropdown
    End Sub
    

    Darrell H Burns
    Tuesday, December 28, 2010 3:25 PM
  • Darrell,

    I think there was a typo in AccessVandal's reply.

    Detail_Paint (as the name indicates) does NOT belong to the form. It belongs to the form's detail section.

    Click on the 'Detail' bar (in design view) and on the property sheet, you will see the OnPaint event.

    As for why your GotFocus code does not work, I suspect the 'FillMinMax' routine.
    Try commenting it out and see what happens.

    Tuesday, December 28, 2010 5:56 PM
  • Hi Alphonse. I know the problem doesn't occur if I don't execute the fill routine. But I have to do the fill, so eliminating it is not an option.

    The conditions that cause the behavior are as follows:

    1. User clicks dropdown arrow
    2. GotFocus event triggers fill routine and closes by invoking the dropdown method
    3. Dropdown flashes

    If the user clicks the arrow again, it stays open. Or, if the user enters the field by tabbing, it stays open.

    I got this response from the Experts Exchange:

    That is the expected behavior.  That’s just what it does … the flash effect.  When you click the arrow directly w/o tabbing in, two things happen:

    1.     The normal arrow click attempts to drop down the list

    2.     The Got Focus kicks in, and your DropDown method immediately tries to drop down the list.

    This is why I don’t use this method.  It’s a Catch 22.  I’ve never seen a solution, as this comes up on Experts Exchange occasionally.

    Rats!


    Darrell H Burns
    Tuesday, December 28, 2010 7:07 PM
  • Darrell,

    I wan't suggesting that you not fill the combobox. Merely try to isolate the problem.

    If it works the way you want without calling that routine, look for somewhere else to invoke the code or possibly modify it. You haven't posted the the code for the fill routine, so no one can see what it is doing.

    Another option is to try the 'OnEnter' event, which occurs before the OnFocus event. I have a combo box where I drop it down in the 'OnEnter' event. It works fine whether user clicks on the arrow or the combo box or tabs into it.
    However, in my case the list is already filled.

     

    Tuesday, December 28, 2010 7:31 PM
  • I didn't examine all the code, so forgive me if I'm off base.  But what if you completely filled the box and then dropped it down?

    "The secret of getting ahead is getting started. The secret of getting started is breaking your complex, overwhelming tasks into small, manageable tasks, and then starting on the first one" - Mark Twain

    "Twenty years from now you will be more disappointed by the things you didn't do than by the ones you did. So throw off the bowlines. Sail away from safe harbor. Catch the trade winds in your sail. Explore. Dream. Discover." - Mark Twain

    Please mark/unmark posts if they answered/unanswered your question as these are helpful to other users of this forum. ~ SuzyQ (aka Terry S.)

    Tuesday, December 28, 2010 7:33 PM
  • Darrell,

    If the "fill routine" is refreshing/requerying the form, it will cause the combobox to roll back up.

    I guess you'll have to find out whether that's the case, else you'll be going round in circles.

    Try to post the routine code and all the form's code here if that's possible. Your routine might be the reasons why it's circumventing the form's event.

    Wednesday, December 29, 2010 1:02 AM
  • OK, you asked for it...

    (BTW, it behaves the same way with OnEnter.)

    Private Sub fldMinVal_GotFocus()
      FillMinMax "Min"
      If IsNull(fldMinVal) Then
        fldMinVal.Dropdown
      End If
    End Sub
    
    Private Sub FillMinMax(Which As String) 'Clears and refills the Value List in either the MinVal or MaxVal dropdown. Called as each control gets focus.
      Dim ctlName As String
      Dim rLookup As Recordset
      Dim n As Integer
      If Which = "Max" Then
        ctlName = "fldMaxVal"
      Else
        ctlName = "fldMinVal"
      End If
      On Error Resume Next
      n = Me.Controls(ctlName).ListCount
      '1. Clear out the old values...
      Do While Me.Controls(ctlName).ListCount > 0
        Me.Controls(ctlName).RemoveItem (n)
        n = n - 1
      Loop
      '2. Fill the list...
      If fldDataType = 9 Then 'binary
        Me.Controls(ctlName).AddItem "True"
        Me.Controls(ctlName).AddItem "False"
        Exit Sub
      End If
      Set db = CurrentDb
      If Not fldIsDependent And Nz(fldLookupSource) > "" Then 'no list if the field is dependent
        Set rLookup = db.openRecordset(fldLookupSource)
        Do While Not rLookup.EOF
          Me.Controls(ctlName).AddItem rLookup.Fields(0)
          rLookup.MoveNext
        Loop
        rLookup.Close
      End If
      db.Close
      Set db = Nothing
    End Sub
    
    

    Darrell H Burns
    Wednesday, December 29, 2010 1:12 AM
  • Terry -- I will when I get an answer.
    Darrell H Burns
    Wednesday, December 29, 2010 1:14 AM
  • Darrell,

    Have you tried filling the list in the OnEnter event and dropdown in the OnFocus event?

    Is there some other event (like current, as previosly suggested) that could trigger the fill, prior to user getting to the combobox? Then dropdown in the enter event.

    Doing it all together seems like it isn't going to work because of event/action conflicts. Therefore, you need to rethink.

    Wednesday, December 29, 2010 1:50 AM
  • Have you tried filling the list in the OnEnter event and dropdown in the OnFocus event?

    Yeah, exactly the same behavior.

    Is there some other event (like current, as previosly suggested) that could trigger the fill, prior to user getting to the combobox? 

    Since each row has its own list values, I have to fill the dropdown as soon as I detect that the user has moved to another row. What would be nice is if there was a way to intercept the dropdown click event at the row level, before it reaches the combobox's GotFocus.


    Darrell H Burns
    Wednesday, December 29, 2010 2:29 AM
  • Darrell,

    AFAIK, in my experience with combobox. The "AddItem" and "RemoveItem" cause the combobox to requery.

    Maybe you should re-code to something like this

    Private Sub fldMinVal_GotFocus()
      FillMinMax "Min"
    End Sub

    Since the routine is in the form's module, add these at the bottom of the routine.....

      End If
      db.Close
      Set db = Nothing

    Me.Controls(ctlName).Setfocus

    Me.Controls(ctlName).Dropdown

    End Sub

    Hope it works for you.

    • Edited by AccessVandal Wednesday, December 29, 2010 2:43 AM code at wrong line
    Wednesday, December 29, 2010 2:42 AM
  • Darrell,

    As explained from Expert Exchange, the OnEnter and GotFocus will cause the subroutine to run. Is this a good idea?

    If there any other way, can you not use the combobox OnEnter/GotFocus event? Seems like a convoluted way of inserting ValueList. Why remove and re-insert same values again?

    Wednesday, December 29, 2010 3:43 AM
  • Your answer may be that every time you add another item it closes.  If you completely fill it and then drop it down, you may resolve the problem.  Have you tried - Actually - this probably won't help anyway because it looks like you are doing what I suggested above.  You're just doing it in the same procedure.

    Private
     Sub
    
    
     fldMinVal_GotFocus()
    FillMinMax "Min" End Sub
    private sub fldMinVal_enter()
    If IsNull(fldMinVal) Then fldMinVal.Dropdown
    End If end sub

    "The secret of getting ahead is getting started. The secret of getting started is breaking your complex, overwhelming tasks into small, manageable tasks, and then starting on the first one" - Mark Twain

    "Twenty years from now you will be more disappointed by the things you didn't do than by the ones you did. So throw off the bowlines. Sail away from safe harbor. Catch the trade winds in your sail. Explore. Dream. Discover." - Mark Twain

    Please mark/unmark posts if they answered/unanswered your question as these are helpful to other users of this forum. ~ SuzyQ (aka Terry S.)

    Wednesday, December 29, 2010 5:12 AM
  • Same result.

    I'm throwing in the towel. Thanks for trying.


    Darrell H Burns
    Wednesday, December 29, 2010 1:21 PM
  • You say that you need to fill the dropdown when the user has moved to another row. If that is the case then you should be able to fill the dropdown in the form's OnCurrent event and then do the dropdown in the OnEnter event of the combo.

    If the combo needs to be re-filled when the data in another field is entered/changed, then re-fill in the afterupdate event fot that field.

    Wednesday, December 29, 2010 1:27 PM
  • Darrell,
     
        Whenever programmatic drop down of look-up list for a combo box is to be effected, it is important to have no distraction sandwiched between the two pertinent actions i.e. setting focus followed by that for actual drop down. These two actions should be treated as an integral block.
     
        Accordingly, you could try with slightly modified code as follows:
    '=======================
    Private Sub fldMinVal_GotFocus()
        FillMinMax "Min"

        If IsNull(fldMinVal) Then
            fldMinVal.SetFocus
            fldMinVal.Dropdown
        End If
    End Sub
    '=======================
     
    Best wishes,
    A.D.Tejpal
    ------------
     
    ----- Original Message -----
    Newsgroups: Msdn.en-US.accessdev
    Sent: Wednesday, December 29, 2010 06:42
    Subject: Re: Why won't ComboBox dropdown stay down?

    OK, you asked for it...

    (BTW, it behaves the same way with OnEnter.)

    Private Sub fldMinVal_GotFocus()
     FillMinMax "Min"
     If IsNull(fldMinVal) Then
      fldMinVal.Dropdown
     End If
    End Sub
    
    Private Sub FillMinMax(Which As String) 'Clears and refills the Value List in either the MinVal or MaxVal dropdown. Called as each control gets focus.
     Dim ctlName As String
     Dim rLookup As Recordset
     Dim n As Integer
     If Which = "Max" Then
      ctlName = "fldMaxVal"
     Else
      ctlName = "fldMinVal"
     End If
     On Error Resume Next
     n = Me.Controls(ctlName).ListCount
     '1. Clear out the old values...
     Do While Me.Controls(ctlName).ListCount > 0
      Me.Controls(ctlName).RemoveItem (n)
      n = n - 1
     Loop
     '2. Fill the list...
     If fldDataType = 9 Then 'binary
      Me.Controls(ctlName).AddItem "True"
      Me.Controls(ctlName).AddItem "False"
      Exit Sub
     End If
     Set db = CurrentDb
     If Not fldIsDependent And Nz(fldLookupSource) > "" Then 'no list if the field is dependent
      Set rLookup = db.openRecordset(fldLookupSource)
      Do While Not rLookup.EOF
       Me.Controls(ctlName).AddItem rLookup.Fields(0)
       rLookup.MoveNext
      Loop
      rLookup.Close
     End If
     db.Close
     Set db = Nothing
    End Sub
    
    

    Darrell H Burns

    A.D. Tejpal
    Thursday, December 30, 2010 2:03 PM
  • Hi Darrell,

    At the risk of sounding stupid, have you considered filling a list box instead of a combo box. You can still check a list box for selection of 1 or more rows and you can still light off a procedure of function based on the selection the same way.

    The advantage is that you don't have to deal with the interface changing. It's shape is static and you can continue to add files to it to till the cows come home.

    Hope that helps.

    Steve


    Steve Robinson
    Thursday, December 30, 2010 5:33 PM
  • Folks - I have found a solution to prevent the dropdown "flash". The following code will allow the dropdown to be filled on entering the control either by tabbing in or by clicking the dropdown arrow:

    Private Sub fldMinVal_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      DoCmd.CancelEvent '1. Cancel MouseDown to avoid dropdown "flash"
    End Sub
    
    Private Sub fldMinVal_Enter() '2. Use Enter instead of GotFocus to avoid dropdown "flash"
      FillMinMax "Min"
      fldMinVal.SetFocus '3. SetFocus manually to avoid dropdown "flash"
      If IsNull(fldMinVal) Then
        fldMinVal.Dropdown
      End If
    End Sub
    
    

     

    Thanks everybody who tried helping me out with this dilemma!

    DDD


    Darrell H Burns
    Friday, December 31, 2010 2:24 PM
  • I know this is an old thread but I want to add my two bits.

    I wrote some code that rewrote the RowSource for the combo as the user would type, using the KeyPress event. This allows me to give the impression of AutoComplete or AutoSuggest to the user. In order to make this work, I run the DropDown method every time after changing the RowSource.

    On one form this wasn't working properly. I was getting the flash problem. I found out that the unexpected behavior was caused by my conditional formatting. Incidentally, the conditional formatting was set for the OnFocus event but apparently if a conditional formatting rule exists then something happens every time a key is pressed. This was causing the DropDown method to appear not to work.

    Thursday, April 26, 2012 12:32 AM