Date and Time Picker

GPatters

New member
Local time
Today, 09:38
Joined
Jan 4, 2008
Messages
3
I have been viewing the posts on this forum for the past couple of months while developing a new porject, and I must say that they have been a great help; I've learned a ton!

To 'give back to the community' so to speak, I decided to post some info regarding some challenges that I had with the Microsoft Date and Time Picker control, and how I resolved these issues.

My first challenge was that I wanted to be able to differentiate between records that had values in them from others that didn't. I would always get an error message advising me that the control could not contain a null value if the CheckBox property was false.

I resolved this issue by right-clicking on the control in design view and selecting properties. I then clicked on the 'Other' tab and changed the CheckBox property to 'yes'. This places a small checkbox in the textbox portion of the control that the user must click before entering a value. If the checkbox is empty then the control value is null.

To make my database a little more user friendly, I also wanted the date picker calendar window to open up automatically. This would allow the user to simply pick a date and move on instead of having to click the checkbox, click the drop down button, and then enter a date.

The easiest method I was able to find for this was to use SendKeys to automate the keystrokes required to open the control. The code looked something like this:

me.dtpThisDate.setfocus
sendkeys "%{DOWN}"

This automated the ALT-DOWN key combination otherwise required to open the control (% = ALT key, {DOWN} = down key). Looking up the SendKeys method in the Access help file also gives a fairly exhaustive list of other key references.

Lastly, I wanted to be able to reset the value of the date picker and set it back to null under certain conditions. Again, I used SendKeys to accomplish this. The keystroke required to change the checkbox value was SPACEBAR, so I used the following code to reset the control:

me.dtpThisDate.setfocus
me.dtpThisDate.value = date()
sendkeys "{ }"

I imagine it seems a little redundant to post a thread on here after you've already figured out how to solve the problem, but it took me a few hours to play around and find the solution myself; hopefully this will save a few people some time. :)
 
Welcome to the board :)

Thanks for posting a solution and for using the search function of the board to get the information you needed in the past.
 

Users who are viewing this thread

Back
Top Bottom