Onchange event in bound textbox

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:37
Joined
Jan 20, 2009
Messages
12,895
I have a textbox with the control source bound to a query. It also has an onchange event procedure that is meant to lookup values for other textboxes based on the number in the bound textbox.

When I change the current record in the query, the bound box changes too but it does not trigger the onchange event procedure, presumably because the content of the box hasn't actually changed. It is still the same expression even though the displayed value changes.

Is there a way to trigger an event in a bound textbox when the displayed value changes?
 
>>>Is there a way to trigger an event in a bound textbox when the displayed value changes?<<<

I understand that this text box is bound to a query, so to reiterate your question in a slightly different way, you want a trigger when you change from one record to another with the next record or previous record button.

If that's the case then the event you are looking for is called the "current event" it is of the actual form.
 
>>>I understand that this text box is bound to a query, so to reiterate your question in a slightly different way, you want a trigger when you change from one record to another with the next record or previous record button.

Not quite. The query results are displayed in datasheet view inside a subform. When I click a line in that view it changes the value in the bound textbox but I want to also update the other textboxes which are meant to be triggered by the change.

I can't bind these because they need to be used as input boxes to update the records.
 
I don't understand how your bound textbox is updating. If the bound textbox is part of the subform, then it's display will update when the user moves to a different subform record AND it will fire the OnChange event (unless the next record happens to have the same value whence it won't fire since the value didn't change).

If the bound textbox is part of the main form, then neither should happen. It shouldn't even update.
 
Last edited:
Maybe my terminology is incorrect. I am fairly new to this side of Access. It didn't say "unbound" in the box in design view. But I guess maybe that doesn't mean it is bound in the strict sense of the word?

More specifically the text box has a datasource:
Forms!Formname.subformname("fieldname")

It follows the current record in the subform whose record source is a query.

OnChange events are not triggered by changes in the text box displayed data. The same code connected to a button click does work.

Thanks for your help. Sorry if I have confused the description of the problem.
 
I think the problem is that I don't use databinding so I don't understand how it works. Maybe I won't be able to assist.


I just tried to reproduce your scenario with no luck. I dropped a textbox on the main form and set its "ControlSource" to:

Forms!Form1!subform1.Controls("LastName")

But all I get is a ?Name-error in the textbox. I do not see a datasource property, not even in Intellisense.
 
Last edited:
>>>I don't use databinding so I don't understand how it works.

That makes two of us at least.

>>> Forms!Form1!subform1.Controls("LastName")

This would be your equivalent of what I have:
Forms!Form1!subform1.("LastName")

Source Object for the subform is a table/query with a field "LastName"

The subform Wizard creates another form as the Source Object. I change the Source Object to a query in the properties of the Subform.

Hope this makes sense.
 
I've not really been following this thread properly, but I noticed your final comment...
>> I change the Source Object to a query in the properties of the Subform.

You're using a subform control bound to a Query?
You'll not be able to react to events therein. That's the tradeoff.
Events are raised by form UI interactions. The query bound datasheet is a hack which lets us get away with not creating a form to display our data - it's quick and convenient.
But the events which we use in forms aren't available.
(You can try hooking into the events as an implicitly created subform object by Access - but the events are just not raised as they would be for a form).

If you're not using Access default data binding though - then I don't quite see how you're changing records etc other than through manual code navigation.
As I mentioned - I find this thread a little unfocussed. A physical example would likely help someone to help you more definitively.
 

Users who are viewing this thread

Back
Top Bottom