OnChange event

M

Matt

I have a form that has 3 combo boxes. The user first selects a value in CMB1,
which will update the values in CMB2 (CMB2 values are dependent on CMB1).
The user could also select a value in CMB3 that will automatically set the
values in CMB1 and CMB2 instantaneously. If the user selects CMB1 and CMB2,
there is an OnChange Event ran in VB, which works fine. However, if I use
CMB3 to automatically set the values in both combo boxes, the OnChange Event
does not work. I also tried using the AfterUpdate Event and no good. Any
suggestions on how to intitalize the OnChange Event?

Thanks,
Matt
 
W

Wayne Morgan

The two events don't run if you change the control's Value by code. They do
run when you change the control's Text property, not its Value property. To
change the control's Text property, the control must have the focus.

Another option is to just call the other code procedure after you make the
change.

Example:
CMB1="Hello"
CMB1_AfterUpdate

If you try to do this from somewhere other than the form that has the
control, you'll need to change the procedure you're calling from a Private
to a Public procedure.

You could also place the code in the AfterUpdate procedure in a procedure in
a standard module and call it from either the AfterUpdate event or from the
code you are using to make the changes to the control.
 
M

Matt

I am trying to make the .Text code work, however I am getting an error. When
I run it the error message states "The macro or function set to the
Beforeupdate or ValidationRule property for this field is preventing Access
from saving the data in the field". i checked and there is no BeforeUpdate
or ValidationRule applied. Any suggestions?
 
W

Wayne Morgan

As mentioned, for .Text to work the control has to have the focus. Since
that isn't the error you're receiving, then that's probably not the problem.
The other then to be aware of is that using the Change event and changing
the .Text through code can set up an infinite loop.

Usually, the error you're getting is caused as mentioned or if the data type
is wrong for the field. A Validation Rule would be a restriction placed on
the field in the table's design. If you're trying to "build" a value in the
..Text, say one letter at a time, it may be that the intermediate steps may
not meet the Validation requirements.
 
M

Matt

Thanks for your help, I finally got to work. I ended up creating a CMD
button to inititalize the event. Thanks again.
 

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