combobox drops down when I don't want it to

jillrein

Registered User.
Local time
Today, 13:55
Joined
Apr 19, 2008
Messages
28
I would be very grateful if anyone can help me.

I have an unbound combo box on a form. Users are allowed to add new items. Limit to list is set to true and auto expand is false. When the not in list event is triggered I have vb code that allows the user to add a new item and then requeries the combo box. The problem is that when a new item is entered, the combo box drops down automatically but I don't want it to. I tried to find out where it was happening in the code by including breakpoints but as soon as there is a breakpoint even after the requery, then the box does not dropdown.
 
It'd probably help us to see the pertinent NotInList code.
 
Here is the subroutine and the function that it calls.



Private Sub ComboClass_NotInList(NewData As String, Response As Integer)

Response = NewListItem("Class", "comboClass", NewData, "class", Response, True)
If Response = vbYes Then

Me.[Class] = NewData
DoCmd.RunCommand acCmdSaveRecord

IsNewClass = True
Me.ComboClass.Requery

End If
End Sub


Function NewListItem(formname As String, fieldname As String, _
NewData As String, item As String, Response As Integer, msgneeded As Boolean)
' if new data entered in combo box
Response = acDataErrContinue
On Error GoTo NewListItem_notinlist_err
Beep

If msgneeded Then
NewListItem = MsgBox("Add New " & item & "?", vbYesNo, "New " & item)
Else: NewListItem = vbYes
End If
If NewListItem = vbYes Then
DoCmd.GoToRecord acForm, formname, acNewRec
Forms(formname).Controls(fieldname) = NewData



End If
NewListItem_notinlist_Exit:
Exit Function
NewListItem_notinlist_err:
MsgBox Error$
Resume NewListItem_notinlist_Exit
End Function
 
In thinking this over, it really makes sense that the combobox drops down. It's doing so to show the item you just added. Access assumes since you added the item to the box, you want to also select it, that being the whole idea behind NotInList.

That aside, I suppose at the end of your code you could move the focus to another control on the form and the dropdown would close.
 
Thanks for taking time on this one. The problem is that I do attempt to move the focus to the next control but the dropdown seems to interrupt it - and cover the next control as well. Perhaps I will redesign my form!
 

Users who are viewing this thread

Back
Top Bottom