469,927 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Combo Box Rowsource set at GotFocus

I have a combo box on a form. It uses the GotFocus event to poopulate
the rowsource with a value list that is created on the fly in VBA. Fine
and dandy, except, is a user opens another form and returns to the form
with the rowsource, the rowsource is not refreshed because the combo
box doesn't execute the GotFocus event because it has never lost the
focus.
If I put the code to generate the value list in the MouseDown event of
the combo box it repopulates the value list just fine each time a user
clicks the combo box, but then it doesn't determine the item selected
from the combo box.
Sort of frustrating but I'm sure there's a simple solution to this?
Thanks,
lq

Nov 13 '05 #1
6 3805
Try having the form's GotFocus event call the combobox's GotFocus event.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"lauren quantrell" <la*************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have a combo box on a form. It uses the GotFocus event to poopulate
the rowsource with a value list that is created on the fly in VBA. Fine
and dandy, except, is a user opens another form and returns to the form
with the rowsource, the rowsource is not refreshed because the combo
box doesn't execute the GotFocus event because it has never lost the
focus.
If I put the code to generate the value list in the MouseDown event of
the combo box it repopulates the value list just fine each time a user
clicks the combo box, but then it doesn't determine the item selected
from the combo box.
Sort of frustrating but I'm sure there's a simple solution to this?
Thanks,
lq

Nov 13 '05 #2
No luck with that. The Form's GotFocus event doesn't trigger. BTW-What
I'm populating the combo box with is a list of all open Access forms.
Even though I click other controls to open other forms, when I click
back on the switchboard form that contains the offending switchbox, it
doesn't trigger the GotFocus event of the list box unless I click
another control on the form first.

Nov 13 '05 #3
On Sun, 7 Aug 2005 13:57:17 -0400, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:

Perhaps the form_activate event would help. Depends on what kind of
form it is.

You could always offer a "refresh" button.

-Tom.

Try having the form's GotFocus event call the combobox's GotFocus event.


Nov 13 '05 #4
Most of my forms are popup forms so this doesn't allow the GotFocus
event to trigger as it otherwise would.
So what I have done is written code in the OnMouseMove event:

Sub myComboBoxName_OnMouseMove

Dim myString as String, myValue as string

For each i in ...
'code here to extract each value...
myString = myString & ";" & myValue
Next i

If myString <> Forms!myFormName.myComboBoxName.RowSource Then
Forms!myFormName.myComboBoxName.RowSource = myString
End If

End Sub

This works fine however as you can see, the code is looping as long as
the mouse is over the combobox control, though it will only set the
rowsource once, so the user doesn't notice.

I need to figure out a way so that it only loops once as well...

Thanks,
lq

Nov 13 '05 #5
lauren quantrell wrote:
I have a combo box on a form. It uses the GotFocus event to poopulate
the rowsource with a value list that is created on the fly in VBA. Fine
and dandy, except, is a user opens another form and returns to the form
with the rowsource, the rowsource is not refreshed because the combo
box doesn't execute the GotFocus event because it has never lost the
focus.


Then do what I do. Make the code that generates from the ongotfocus
event of the combobox a standalone code in a standard module. In the
pop up form where you're performing actions that may affect the sql of
the combobox in question, pop in that code.

In doing such things, I always have the code in standard modules in case
the afterupdate events of other controls elsewhere needs to fire the
rebuild of the combo box.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #6
Tom van Stiphout wrote:
On Sun, 7 Aug 2005 13:57:17 -0400, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:

Perhaps the form_activate event would help. Depends on what kind of
form it is.

You could always offer a "refresh" button.


I generally go for a "(refresh)" option at the end of the list if space
is at a premium or if the combo box is on a command bar.
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sean | last post: by
4 posts views Thread by jcazmail-groups | last post: by
3 posts views Thread by Antoine Janssen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.