unbound textbox value derived from subform

R

Ron

I've got an unbound text box, txtLatestDate on a main form intended to show
the latest date from a series of dates in a subform. Using comboboxes, the
subform shows a status and a date, several for each related record on the
main form. Using VBA, I use DMax to find the latest date and set
me.parent.txtLatestDate equal to it. It works, BUT I can't seem to get
txtLatestDate to refresh as soon as I change an existing date in the subform
(to a later value than any other). I've tried

me.parent.txtLatestDate = (DMax expression)
me.parent.requery

from several different events (onclick, dirty, afterupdate, etc.) But only
after picking the date twice does the refresh occur. How do I get it to
occur instantly?

And a corollary question. I notice that when I delete "event procedure"
from the control source property (in this case, a text box), the underlying
event code is still in the VBA. Does this mean that it is executing even
though there's no indication that it exists in the control event property?!?

Thanks, -Ron
 
R

Ron

Fixed my own problem. In the change event for the combobox, this does it:

me.refresh
me.parent.txtLatestDate = (DMax expression)

Not sure why the refresh is needed, since the (join) table to which the
cboBox is bound (which is also the domain of the DMax expression) appears to
update instantly upon picking a new value for the combobox. But I shoulda
known the difference between .requery and .refresh :(

Still would like to know if there's a setting that auto deletes event code
when the property is cleared in the form's design view.

-Ron
 
R

Rob Parker

Hi Ron,

No, there's no setting to automatically remove code when the Event Procedure
entry is removed. And, IMHO, that's a very good idea, because sometimes the
Event Procedure entry will get removed by accident, and I'd prefer not to
have to reprogram it all - particularly for some of the large, complicated
subroutines which I have, which may have taken days (or months) to
fine-tune.

If the Event Procedure entry is removed, the code will never be run.

HTH,

Rob
 
R

Ron

Hi Rob,
No, there's no setting to automatically remove code when the Event
Procedure entry is removed. And, IMHO, that's a very good idea, because
sometimes the Event Procedure entry will get removed by accident, and I'd
prefer not to have to reprogram it all - particularly for some of the
large, complicated subroutines which I have, which may have taken days (or
months) to fine-tune.

Makes sense, thanks.
If the Event Procedure entry is removed, the code will never be run.

Aha. Good to know! So if I ever get sufficiently proficient to be popping
in subs while strolling through the coding windows (fat chance :) ), I'd
better remember to "activate" them in the form design. Thank you.

-Ron
 
J

John W. Vinson

Fixed my own problem. In the change event for the combobox, this does it:

me.refresh
me.parent.txtLatestDate = (DMax expression)

Nitpick: I'd use the AfterUpdate event (which fires when a selection is made),
rather than the misleadingly-named Change event (which fires at every
keystroke or mouseclick).
 
R

Ron

Even clicks in a datepicker? But will do, thanks John.

Would appreciate hearing any generalized advice as to when/why me.refresh is
needed for stuff like this. As mentioned above the table to which is bound
the "me" control (a textbox with a datepicker, not a combobox as I implied
above) appears updated immediately. ie. I change the date in "me," click on
that table's tab, and the new date is there. Perhaps there is some buffer
that nevertheless needs a clearance that only the refresh provides?

-Ron
 

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