On change event for a combo box (1 Viewer)

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
I want to do something with a control if another control changes. The other control is a combo box. When it changes I want to store the changed value in another control. There is a reason!!

So I bascially have

Me.atextcontrol = Me.acombocontrol.Column(1)

The combo box displays a list of records from another table

I've noticed some weird things by putting a break on the above line in the code.
If I select another one of the records in the combo box then Me.acombocontrol.Column(1) contains exactly what it should do.
If I happen to hit the space or delete key when highlighting the combo box record I would expect NULL or spaces in Me.acombocontrol.Column(1). I'm getting the old value.
If I happen to say add a character to the existing text (i.e I have say Fred and I manage to stick a 2 on the end giving Fred2) then I would expect to see that (Fred2) in Me.acombocontrol.Column(1). I'm getting NULL.

Any ideas why I'm seeing what I'm seeing. I want to cater for it in the code and display errors where appropriate and at the moment I'm not picking up the right erros.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:26
Joined
Aug 30, 2003
Messages
36,124
You want the after update event, not the change event. The change event fires with every keystroke.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:26
Joined
Aug 30, 2003
Messages
36,124
By the way, if the change event was appropriate, you'd need the .Text property of it:

http://www.baldyweb.com/ValueText.htm

That's why you're not getting the updated value in the changed event.
 

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
You want the after update event, not the change event. The change event fires with every keystroke.

Ah OK thanks - wonder why it's been coded under the change event. When would you use the change event then?
 

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
By the way, if the change event was appropriate, you'd need the .Text property of it:

http://www.baldyweb.com/ValueText.htm

That's why you're not getting the updated value in the changed event.

Thanks that's worth knowing!!
On your page you have ".Value is that the former contains the current control data, and the latter contains the last saved " that doesn't explain the contents of my 3 examples. I presume mine are.values it being the default?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:26
Joined
Aug 30, 2003
Messages
36,124
Yes, .Value is the default so in the change event this:

Me.atextcontrol = Me.acombocontrol.Column(1)

is giving you the previous value, not the space just typed in. The change event isn't used as much as the update events. Things like "find as you type" would be done from the change event so each character typed affected the result.
 

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
Yes, .Value is the default so in the change event this:

Me.atextcontrol = Me.acombocontrol.Column(1)

is giving you the previous value, not the space just typed in. The change event isn't used as much as the update events. Things like "find as you type" would be done from the change event so each character typed affected the result.

OK one question. When I change say Fred to Fred2 this ultimately fails and is highlighted by a system error that it's not in the list. However it still triggers the change event and at that time contains NULL? I don't understand.
 

Minty

AWF VIP
Local time
Today, 03:26
Joined
Jul 26, 2013
Messages
10,366
It will trigger the change event, but not the after update event.

Change event is based on keyboard input, not data Update. The Value will be whatever was in the control before the change event fires.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:26
Joined
Aug 30, 2003
Messages
36,124
Was the previous value Fred, or you mean you typed Fred2? If the previous value of the control was Fred, that's what I'd expect returned by the code. If you never hit enter or tab or clicked into another control, it would still be null.
 

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
Was the previous value Fred, or you mean you typed Fred2? If the previous value of the control was Fred, that's what I'd expect returned by the code. If you never hit enter or tab or clicked into another control, it would still be null.

Fred was a value in the dropdown box (using select field from table etc). WHen I change it to fred2 i get NULL. If I blank it out I get the original.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:26
Joined
Aug 30, 2003
Messages
36,124
Can you attach a db here we can play with?
 

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
It will trigger the change event, but not the after update event.

Change event is based on keyboard input, not data Update. The Value will be whatever was in the control before the change event fires.

Is there a list of what triggers what and also what you can and can't do in an event. I keep hitting the same problems so if there is a article on the subject would be great.
 

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
Can you attach a db here we can play with?

I will do. Just called to something more urgent. I'll send when I get back on it. I've got round the problem in the meantime but would be useful for future reference.

I'll be back
 

Minty

AWF VIP
Local time
Today, 03:26
Joined
Jul 26, 2013
Messages
10,366

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
It's not a short list https://support.office.com/en-gb/ar...-objects-e76fbbfe-6180-4a52-8787-ce86553682f9

but should help.

I'm intrigued to see your DB as well, as when I tested it here, I got the previous value of the control in the change event, as Paul expected to.

Thanks and I will when I've finished what I'm on. I've got around the problem any way but I'll send something over if I can recreate it!!
Basically what I'm doing is I have a form bound to table x. One of the controls is a combo box with the country id from a table (countries!!). The record source is therefore the countries table. I display the country name rather than the id. If for example this particular record is showing France and I change it to France2 the above behavior is displayed. I have got around this for the moment by making one of the attributes Limit to List Yes. This now throws up a system message. I would prefer to trap this myself but at the moment I'm time constrained.
I'll get something uploaded either over the weekend or early next week
 

ryetee

Registered User.
Local time
Today, 03:26
Joined
Jul 30, 2013
Messages
952
pbaldy and minty
I've tried to replicate my scenario but the behaviour is as pbaldy says. I don't have the original as I changed it beyond belief to get it to work. So thanks for all the help.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:26
Joined
Aug 30, 2003
Messages
36,124
Glad you got it sorted.
 

Users who are viewing this thread

Top Bottom