Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Problem

Status
Not open for further replies.

Domino2

Technical User
Jun 8, 2008
475
GB
I have some code that refuses to dropdown a combo when returning from a messagebox. I have tried moving focus away from the control to a textbox that onfocus tries to drop the combo but nothing works? Any ideas, thanks

Private Sub Combo1_Click()
If MsgBox("You selected " & Me.Combo1.Value & " is this correct?", vbYesNo) = vbYes Then

Else
Me.Combo1 = Null
Me.Combo1.SetFocus
Me.Combo1.Dropdown

End If

End Sub
 
The code in the else block works if there is no message box or if statement? I'm not sure the code will work on that event but I could be wrong.

If it does, you might try adding a Me.Setfocus as the first line in the else. If it doesn't, you might consider the afterupdate event or the Gotfocus event.
 
Many thanks. Tried everything, but nothing seems to work.The combo goes into a dropdown for a split second and then closes. I removed the not in the list event, but it did not fix it. There are no other events on the combo.!!!
 
I moved the code to afterupdate event, the combo still opens for split second then closes?
 
In Access 2003 I confirmed the dropdown method does not work on the following events...

On_Click
After_Update
Lost_Focus


It does appear to work On_Got_Focus. I suggest you try that, assuming you are wanting to test the default values.
 
Still cannot make it dropdown and stay open/down. I even tried setting focus to a dummy textbox with the dropdown event in it's got focus but still thesame. Driving me mad. Can anyone get it to work themselves? Thanks
 
I've created the same code and it works perfectly. If the dropdown opens, then closes, it seems there must be more code that continues to run. Put in a breakpoint and find out what happens when it gets to the dropdown method.


Randy
 
Try it without setting the combo to null.

I tested the two lines in other events and the dropdown method on got focus and it works... Although I didn't set the value of the control.
 
I don't care for using SendKeys but it should work in this instance. Assuming a combo box named cboDate, try:
Code:
Private Sub cboDate_AfterUpdate()
    If MsgBox("You have selected " & Me.cboDate & ". Is this correct?", vbYesNo + vbQuestion, "OK") <> vbYes Then
        SendKeys "{tab}"
        SendKeys "+{tab}"
    End If
End Sub

Private Sub cboDate_GotFocus()
    Me.cboDate.Dropdown
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Thanks Duane, I will give it a try, but don't usually like sendkeys.

Thanks lameID, I tried this but it just ends with focus on the combo, the previous selection highlighted, no dropdown.
 
Ureka, this works

Private Sub Combo1_BeforeUpdate(Cancel As Integer)
If MsgBox("You selected " & Me.Combo1.Value & " is this correct?", vbYesNo) = vbYes Then

Else
Cancel = True
Me.Combo1.Dropdown

End If
End Sub

The afterupdate does not work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top