(Q) I have a form with a date field or a
block of code that needs to
input a date and I want to the user to have a calendar view to
select
that date from. I don't want to use any ActiveX components.
(A) Use the Access Date Picker.Download the attached database
and import the form "DatePicker" and the
module "mdlDatePicker" into your project.
Make a CommandButton next to the form's TextBox containing the
date and
add some code to its Click event like this:
Private Sub DateButton_Click() InputDateField DateTextBox, "Some prompt" End Sub
(You might want to use Access' built-in "Calendar" icon as the
CommandButton's picture, and leave the caption blank.)
If you have a block of code that needs to stop and ask for a
date as it
runs, do something like this:
Private Sub SomeAction() Dim d As Variant
' Initialize whatever needs initializing d = InputDate("Some prompt")
' d is now a date (IsDate(d) = True) or Null, if the user ' cancelled.
' Do something with useful with d.
End Sub
InputDateField() will not affect the specified TextBox if the
user
clicks the Cancel button on the DatePicker form. Likewise you
must be
aware that InputDate() will return a Null value instead of a
date if the
user clicks Cancel and your code must handle it appropriately.
Other features include specifying the initial date that the
DatePicker
form presents to the user. See the readme file for more details.
Download DatePicker
|