0
votes

On a normal textbox, I usually use the AfterUpdate event to perform some action. That means the user has to press Enter or Tab after typing, or click in another control, and I have always been happy with that behaviour.
Now I am setting up a Date filter in the header of a continuous form in Access 2010, and I realize that changing the date through the little calendar that comes automatically, does NOT fire the AfterUpdate event, forcing to press Enter after selecting the correct date, which is a bit heavy.
Using OnChange would trigger at every character entered, which is not nice either.
Any suggestion ?

4
If you use the little calendar, the On Change event will only fire once, and what is the betting that that is what people will do? - Fionnuala
@Remou: right, but I'd like to leave them the option of typing the date. I tried to use OnChange + checking the number of characters and IsDate(), but that produces messy results...and I don't want to spend half a day on that. The ideal would be to have the "little calendar" firing an event. - Patrick Honorez
I cannot see any way that the little calendar will give you an event, however, the keypress event will only happen when the user types in the control, so with a module level variable, a keypress and a change event, you might just get close. - Fionnuala
Nice hint, I'll try that. Thanks - Patrick Honorez

4 Answers

2
votes

It is a bit late reply but I hope it will help the others. When using textbox as a DatePicker you should use Change Event with your filter.

However when you are checking your textbox like Form_name.TextboxName it will show last picked date. To avoid that and use currently selected one you need to provide current date like Form_name.TextboxName.Text. Careful here because .Text property is sensitive to focus.

...in short:

Form_name.TextboxName - will show last picked date
Form_name.TextboxName.Text - will show currently picked date

1
votes

well, after you select a date from the date-picker, the Change event occurs for the TextBox control. Then, call a sub or function or set focus to another control... to avoid event fires for each pressed key, put something like: if Len(me.activecontrol) < 10 then exit sub

I hope this helps

0
votes

I use LostFocus event in the textbox. It allows to use the calendar tool and alter the content. The User has to leave the textbox sooner or later, isn't it?

0
votes

I use it in this way

Private Sub txt_FirstDate_Change()
    txt_FirstDate = txt_FirstDate.Text
    myfilter
End Sub