On change to populate unbound form data

G

Guest

I have a form with 2 subcontrols (each a form). User inputs required info in
main form combo box, in combo box 1 and then combo box 2. This works great.
Subcontrol2 form contains unbound data fields only, populated on the On
Change event in combo box 2.


When the 1st subcontrol combobox is changed, I am trying to populate the 2nd
subcontrol form with the values based on the 1st and 2nd combobox's (2nd
combobox retains its original value).

To attempt to force the form into working, I have coded an On Change event
on the 1st combobox which does the following :-

1) Stores the value of combo box 2
2) Sets Combobox 2 to another value
3) Populates Combobox 2 with the original value - hope that would trigger On
Change event??
4) Issue a Requery on subcontrol 2 combobox

The values of the combo box change as coded, but the on change event is not
being invoked by the change in value.

Can anyone tell me where I am going wrong please

Cheers,
Steve
 
J

John Vinson

I have a form with 2 subcontrols (each a form). User inputs required info in
main form combo box, in combo box 1 and then combo box 2. This works great.
Subcontrol2 form contains unbound data fields only, populated on the On
Change event in combo box 2.

Note that the Change event's name might be misleading. The AfterUpdate
event may be preferable - it fires when a value has been selected; the
Change event fires at every single keystroke in the control.
When the 1st subcontrol combobox is changed, I am trying to populate the 2nd
subcontrol form with the values based on the 1st and 2nd combobox's (2nd
combobox retains its original value).

To attempt to force the form into working, I have coded an On Change event
on the 1st combobox which does the following :-

1) Stores the value of combo box 2
2) Sets Combobox 2 to another value
3) Populates Combobox 2 with the original value - hope that would trigger On
Change event??

No, it won't: again - Change fires only when the user types or selects
in the combo. Programmatic events won't trigger it.
4) Issue a Requery on subcontrol 2 combobox

The values of the combo box change as coded, but the on change event is not
being invoked by the change in value.

Can anyone tell me where I am going wrong please

Assuming that a) the Change is the right event and b) that it will be
fired when you run your code. Neither is correct!

I'd just move the code from Change to AfterUpdate, and explicitly call
the AfterUpdate event from your code.

John W. Vinson[MVP]
 
G

Guest

John,
Thanks for the help on this, have one question though.
How do I 'explicitly call' the AfterUpdate event on the subcontrol2 combobox
from the code in subcontrol1 combobox On Change event?

Cheers,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top