I have a date picker on my form and I want to update some stuff whenever the user changes the date. I've tried using the On Updated event, but that event doesn't seem to fire when a new date is picked. What am I missing?
Thanks in advance,
~Rin
I have a date picker on my form and I want to update some stuff whenever the user changes the date. I've tried using the On Updated event, but that event doesn't seem to fire when a new date is picked. What am I missing?
Thanks in advance,
~Rin
or try the change event - but if the user types a date, it will fire everytime they enter a character - but you can use the isdate function to check if it is a valid date
if isdate(datectrl.text) then
'update some stuff
end if
I've found that the reason many users prefer typing in a date is that they don't want to have to click on the calendar icon and then click on a date. I've gotten around this, with great success, by having the calendar automatically popping up when the date field receives Focus. The code to do this (and to move Focus to another Control, causing the AfterUpdate event to fire) is simple:
Code:Private Sub DateField_GotFocus() DoCmd.RunCommand acCmdShowDatePicker End Sub Private Sub DateField_Change() Me.AnotherControl.SetFocus End Sub Private Sub DateField_AfterUpdate() 'AfterUpdate code goes here End Sub
If the date Control happens to be the first Control to receive Focus...you'll need these two bits of code, as well:
Code:Private Sub Form_Load() Me.TimerInterval = 1 End Sub Private Sub Form_Timer() Me.TimerInterval = 0 Me.DateField.SetFocus DoCmd.RunCommand acCmdShowDatePicker End Sub
Linq ;0)>
Thanks for the suggestions to use the Change even, but there isn't one. The only events available for the native date picker control in Access 2016 are on Update, Enter, Exit, Got Focus, and Lost focus. From experimentation, it seems that Update fires on Lost focus. While the best solution would be for Microsoft to step up with a Change event, we all know that's not going to happen or it already would have.
Other threads on this forum suggest using a third party date picker and that really seems to be the only solution. I hate to do it because I really prefer the simple appearance of the MS date picker, but I don't see any way around it.
Thanks for the input folks.
~Rin
Ajax was referring to the change event in the textbox but I would still recommend the After update event
The MS date picker is simple but that's also its weakness.
For example if you want to change to a date in 2010 you have to scroll back month by month almost 100 times
That's one reason why a lot of people prefer to type in their own date
Have a quick look at my Better Date Picker - very easy to use and its ...better IMHO http://www.mendipdatasystems.co.uk/b...ker/4594398118
@ridders52,
The Change event from the unbound textbox with a date data type doesn't fire when a date is selected from the associated date picker. It only fires when a date is typed in.
Thanks for the link to that date picker. I'll check it out. It's been a lot of years since I've used a control that wasn't native in Access so I may need some knowledge updates on how to do that.
Thanks for the help,
~Rin
For that reason, you ideally want everyone to type in the date or nobody.
By using a good date picker, the problem should be solved
My version is clearly explained at the link I supplied and as I said very easy to use
For info, mine is not an ActiveX control. It works in any Aceess version and in both 32-bit and 64-bit Access.
Last edited by isladogs; 12-04-2018 at 03:40 AM.
@ridders52,
I'm having trouble adding the control. Probably because I don't really know what I'm doing. I put it into a folder in the MicorsoftOffice/root/Office16/ADDINS directory. I ran the Add-in manager as and administrtor), navigated to the directory, and selected "All Files" to see the control (the .accdb extension wasn't in the list). I tried too add it and got an error saying that the add-in couldn't be installed because it's missing the USysRegInfo table.
Clearly I'm doing something wrong.
~Rin
Its not an add-in
The instructions were on the link I supplied:
For exampleTo use, copy frmDatePicker & modDatePicker to your own database
Its main purpose is to input a date in a form textbox
All you need for that is one line of code in your textbox click event:
Code:Private Sub txtDate_Click() InputDateField txtDate, "Select a date to use this on your form" End Sub
Sorry...that's simply not true! The code I gave was tested on both a Bound and Unbound Textbox formatted/defined as a DateTime Field.
You have to be doing something incorrectly.
Linq ;0)>
Whilst linq is correct, using the Change event is a bad idea if anyone enters or edits the dates direct as it will fire repeatedly.
After update will only fire once whether the date is entered using a date picker or entered direct.
That's true...but I've never had a problem with that, in the apps I've designed. As I said, once the DatePicker pops up automatically, relieving the user of having to use the mouse to bring it up, users, in my experience, prefer to use it over a bunch of characters.
Colin makes a good point about entering grossly historic dates, i.e. ones far in the past...the native DatePicker is not the way to go...but for entering near current dates, it's perfect.
As is often the case...it's a matter of picking the right tool for the job!
Linq ;0)>
As my users often have to pick dates well in the past or future, the built-in date picker isn't up to the job...which is why I rolled my own
I also rarely use the change event but on very rare occasions I've had to resort to code like this to ensure it fired no matter how data was modified
Can't remember what the reason was in that caseCode:Public Sub txtMessage_AfterUpdate() 'This is public so it can be called externally txtMessage_Change End Sub