Example Apps for Businesses, Schools & Developers

A Better Date Picker  

Version 1.5             Updated 27 Mar 2023               Approx 600 kB (zipped)

The built in Access date picker control works in both 32-bit & 64-bit Access.
It was first introduced with Access 2010 to replace the old ActiveX calendar control which was 32-bit only.

AccessDatePicker
Although it does work, there are some issues:
a)   the date picker icon only becomes visible after clicking in a bound date textbox - one extra unnecessary click
b)   months/years can only be changed one month at a time - painfully slow to do if you need to enter e.g. a date of birth
c)   it takes at least 3 clicks to select a date - click the textbox to make the icon visible; click the icon to open the control then click again to select a date
d)   the control doesn't appear for unbound textbox controls (unless these are formatted as dates)
e)   the control cannot be moved on the screen
f)   the control is quite small - particularly for anyone with eyesight issues

The Better Date Picker is designed to improve on the poor functionality of the built-in date picker
It is a replacement date picker with no Active X controls. It can be used in both 32-bit and 64-bit Access.

The original version of this utility was originally posted in this thread at Access World Forums in Jan 2018

The calendar form was loosely based on open source code by Brendan Kidwell from 2003 which can be found at: http://www.glump.net/content/accessdatepicker/

However, I've since made extensive changes to both the appearance and functionality of the calendar form.

If all you want is a visual calendar, it will certainly do that. However, its main purpose is to input a date in a form textbox.

DatePicker
All you need for that is one line of code in the textbox click event:

CODE:


  Private Sub txtDate_Click()
     InputDateField txtDate, "Select a date to use this on your form"   'Modify text as required
  End Sub



The string "Select a date to use this on your form" is used for info on the form and can be adapted to suit.

To use, copy frmDatePicker and modDatePicker to your own application.
Ignore frmMain - its only needed for the example app


Version History

v1.0   30 Jan 2018
          Original release. Days displayed in English from Sun to Sat

DatePickerForm


v1.1   UPDATE - 3 Jan 2022
          Following a request at Utter Access forum, I created an alternative version with the calendar display week starting on Mondays and ending on Sundays.

DatePickerFormM2S


v1.4   UPDATE - 7 June 2022
          Significant changes made following suggestions made by @Kitayama at Access World Forums
          a)   First day of week now automatically assigned according to Windows settings - no need for multiple versions
          b)   Date format automatically assigned according to Windows regional settings
                For example: dd/mm/yyyy (UK); mm/dd/yyyy (USA); dd.mm.yyyy (Germany); d/m/yyyy (Greece); yyyy/mm/dd (Japan)
          c)   Day and month names are displayed using the regional language currently in use.
          d)   Out of month days added in dark grey (optional)
          e)   Days from following month only shown if in same week as last day of current month
          f)   Selecting an out of month day assigns the correct month automatically. Also works successfully for dates selected in previous year or following year
          g)   Clicking the Today button resets the calendar to the current month/year & highlights current date ready for selection to confirm

            Below are 2 examples in Japanese and Greek with different date formats and day order

Japanese: Sun to Sat - date format yyyy/mm/dd

Better Date Picker Japanese: Sun-Sat
Greek: Mon to Sun - date format d/m/yyyy

Better Date Picker Greek: Mon-Sun



          Click to download:       Better Date Picker v1.4     (zipped)



v1.5   UPDATE - 27 Mar 2023
          A further update was made in response to a question by @Psycoperl at Utter Access forum:
          I just wonder is it easy to make the fonts bigger on the calendar since I have users with visual acuity issues with small print.

          The form design is fairly complex with a total of 64 controls (including 42 date buttons)
          Adjusting the size of the form and each of its controls manually would be both time consuming and tedious to do.
          The font size could be hard coded but ideally it should also be adjusted for different screen resolutions.

          However, updating this is very easy to do using automatic form resizing.

          Import the module modResizeForm to your app and then add the following code to the frmDatePicker declarations and the start of the Form_Load event

Private intFontSize As Integer     'font size of date buttons after form resize

'-------------------------------------------

Private Sub Form_Load()

On Error GoTo Err_Handler

'add next 2 lines of code

ReSizeForm Me    'automatically resize form on load
intFontSize = Me.d00.FontSize    'save font size for subsequent redraws

'remaining code follows here....


          When the form is opened, it will be scaled up depending on your screen resolution

Better Date Picker AFR
          NOTE: You can adjust the scaling factor by changing the value of the constant DESIGN_HORZRES in modResizeForm

          In the attached example app, DESIGN_HORZRES = 800
          If your horizontal resolution = 1680, the form & its controls will be enlarged by a scaling factor = 1680/800 = 2.1
          Increase the value of DESIGN_HORTZRES to e.g. 1024 if you wish to reduce the scaling factor (and vice versa)

          For more details, see my series of articles: ResizeForm Me - A Tutorial in Automatic Form Resizing

          However, all the date buttons are redrawn each time the month or year is changed.
          This would result in all the date buttons reverting to the original font size as in design view

Buttons Redrawn
          To fix this, we also need to modify two lines of code in the DrawDateButtons procedure

' This method draws the date buttons on the 7 x 6 grid.
Private Sub DrawDateButtons()
      '...
     'format day colour and set font size
     If I = SelectedDay And txtYear = SelectedYear And cboMonth = SelectedMonth Then
          'current date - highlight it
           Set cmdCurrentDay = btn
           btn.BackColor = ColLemon
           btn.ForeColor = ColDarkRed
           btn.FontWeight = 600
           btn.FontSize = intFontSize + 2     'MODIFIED: set to stored font size value +2pt (was 10)
      Else
          'other dates
            btn.BackColor = ColPaleGrey
           'currently selected month in blue
           btn.ForeColor = ColDarkBlue
            btn.FontWeight = 400
            btn.FontSize = intFontSize     'MODIFIED: set to stored font size value (was 8)
      '...
End Sub


          The form will now retain the font size values each time the buttons are redrawn

Better Date Picker AFR Fixed
          @Psycoperl also had another question in the Utter Access thread:
          Is there a way to provide a starting date for when the field is initially blank? So that it does not default to today?

          By default, the calendar opens at whatever date is specified in the textbox control or is set to today if the date is null.
          This can easily be changed by altering one line of code - also in the Form_Load event

Private Sub Form_Load()
'. . .
      ' if there is a valid date to initialize to, use it.
      'otherwise, default to current or any other specified date
      If IsDate(modDatePicker.InitDate) Then
            myDate = modDatePicker.InitDate
            Me.txtSelectedDate = myDate
            Me.txtSelectedDate.Visible = True
      Else
            myDate = Date    'CHANGE TO WHATEVER YOU WANT e.g. #1/1/2000#
            Me.txtSelectedDate.Visible = False
      End If
      '. . .
      End Sub



          Click to download:       Better Date Picker v1.5 (with AFR)     (zipped)



Video

      I have created a short video comparing the functionality of the built-in Access date picker control with my better date picker.
      You can watch the Better Date Picker video on my YouTube channel or you can click below:

       

      If you liked the video, please subscribe to my Isladogs on Access channel on YouTube. Thanks.



Feedback

      Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

      Also, do let me know if you find any bugs in the application.

      Please also consider making a donation towards the costs of maintaining this website. Thank you



      Colin Riddington                       Mendip Data Systems                       Last Updated 27 Mar 2023



Return to Example Databases Page




Return to Top