Hi Dave,
Ok, here are the step-by-step instructions for using Sensei Stephen Lebans MonthCalendar
version 9.6.
You may not need to do all the steps; just skip the ones that don't apply.
Download either the 97 or 2000 version from this location:
http://www.lebans.com/monthcalendar.htm
(Please bow in reverence on your way in.)
1. Import the five modules (File-->Get External Data-->Import) from the Access 97/2000
demo database into your database.
2. Immediately compile your database before doing anything else! You could introduce
several nasty bugs to your database if your Access version is not completely patched and
up to date so don't skip this step!
3. If you do not know how to compile a database follow these steps:
For Access 97:
- You need to get to any code window. You can do this by either opening any form or module
in Design View and click the button on the toolbar that says "Code". Or type Ctrl-G to
open the VBA editor
- Then you go up to the toolbar and find the option that says: "Debug."
- From that menu you select "Compile and Save All Modules."
For Access 2000, 2002, 2003:
- You need to get to any code window. You can do this by either opening any form or module
in Design View and click the button on the toolbar that says "Code". Or type Ctrl-G to
open the VBA editor
- Then you go up to the toolbar and find the option that says: "Debug."
- From that menu you select "Compile <name of your database>."
What this does is go through ALL your code and look for any possible errors. It will
immediately stop on any problems it finds. Keep in mind that you may have errors in your
database code completely unrelated to Stephen's code. You will need to fix those errors on
your own.
You may likely run into a "References" problem with Stephen's code. The arch-nemesis of
Access is missing references. If you receive a message saying something like "Can't find
project or library" or "Undefined Function" it will most likely be due to the fact that
you do not have a reference set to the DAO object library and/or your file locations for
those libraries are in different places.
To fix the References problem follow these steps:
- Open any module in Design view.
- On the Tools menu, click References.
- At least one Reference should say "Missing". WRITE down the one(s) missing, most likely
it will be the DAO library.
- Click to clear the check box for the type library or object library marked as
"Missing:."
- Close the References Window box.
- Open the References Window back up. Hopefully, nothing should say Missing this time.
- Now go find that library/project(s) in the list that was missing.
- If it is the DAO one scroll down to you get to Microsoft DAO 3.xx and check it.
- If you're using Access 97 that should be DAO 3.51 Object Library.
- If you're using Access 2000, 2002, or 2003 that should be DAO 3.6 Object Library.
- If more than one were missing, find the others and check them as well.
- Close the References box again.
- Now re-compile again. Debug--Compile.
- Hopefully you should not see any more compile errors.
If you'd like to read more about References, here's more info than you could possibly ever
want to know:
http://members.rogers.com/douglas.j.steele/AccessReferenceErrors.html
http://members.iinet.net.au/~allenbrowne/ser-38.html
http://www.trigeminal.com/usenet/usenet026.asp
ACC2002: References That You Must Set When You Work with Microsoft Access
http://support.microsoft.com/?id=283115
ACC97: References That You Must Set When You Work with Microsoft Access
http://support.microsoft.com/?id=175484
ACC: VBA Functions Break in Database with Missing References
http://support.microsoft.com/?id=160870
4. Whew! OK, back to setting up the calendar! Now in your database open any form in design
view that you wish to show the calendar. Go to the code window behind the form. In the
Declarations area (very top) you need to add this code. So the very first few lines of
your code window will look like this:
Option Compare Database
Option Explicit
Private mc As clsMonthCal
' This declares the MonthCalendar Class
' Brought to you by Lebans Holdings: We make the Impossible -> Possible
5. Now go the Form's Load event and enter this code:
Private Sub Form_Load()
' Create an instance of our Class
Set mc = New clsMonthCal
' Set the hWndForm Property
mc.hWndForm = Me.hWnd
End Sub
6. Now go to the Form's Unload event and enter the following code:
Private Sub Form_Unload(Cancel As Integer)
' This is required in case user Closes Form with the
' Calendar still open. It also handles when the
' user closes the application with the Calendar still open.
If Not mc Is Nothing Then
If mc.IsCalendar Then
Cancel = 1
Exit Sub
End If
Set mc = Nothing
End If
End Sub
7. Now find the CONTROL on the form that you wish to have the calendar fill the date.
Right Click on the control and
go to Properties from the list. On the "All" or "Event" tab you should see an option that
says "On Dbl Click". Hit
the little (...) button and it will take you to the code window again. We need to add this
code:
Private Sub txtSelectDate_DblClick(Cancel As Integer)
Dim blRet As Boolean
Dim dtStart As Date, dtEnd As Date
dtStart = Nz(Me.txtSelectDate.Value, 0)
dtEnd = 0
blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
Me.txtSelectDate = dtStart
Else
' Add any message here if you want to
' inform the user that no date was selected
End If
End Sub
In my example above the control was a text box called txtSelectDate. You will need to
change those parts of the code to whatever you have named your control. You could also
assign this to the click event for a text box, but I think using the Double Click event is
a much better idea. A small command button next to a text field could also be used.
8. Compile the code and save the form.
9. Now open the form in regular view and double-click that text box. The calendar should
then appear. Selecting a date on the calendar will cause it to disappear and the resulting
date to be filled into the text field. Simply marvelous isn't it? Please take a moment and
wipe the drool off your face before continuing.
10. Stephen's calendar also allows you to select a range of dates. The way Stephen
designed the code there are actually many ways to accomplish this goal. I will only
present one method, but feel free to experiment with other methods.
This is my personal preference for selecting a date range.
- To do this you will need two text boxes: one to hold the starting date and one to hold
the ending date. Let's call them txtBeginDate and txtEndDate.
- Now create a command button and select cancel if using the wizard. Call it cmdDateRange
and either set a caption property on it or use the little calendar icon for a picture.
(I'll leave any formatting to your tastes).
- Now Right Click on the command button and go to Properties from the list. On the "All"
or "Event" tab you should see an option that says "On Click". Hit the little (...) button
and it will take you to the code window again. We need to add this code:
Private Sub cmdDateRange_Click()
' Retrieve the currently selected date(s).
' Call our Function to display the Calendar
Dim blRet As Boolean
Dim DateStart As Date
Dim DateEnd As Date
' If the control is NULL then use Today's date.
DateStart = Nz(Me.txtBeginDate.Value, Date)
DateEnd = DateStart + 7
' Use named parameters for clarity
blRet = ShowMonthCalendar(clsMC:=mc, StartSelectedDate:=DateStart, _
EndSelectedDate:=DateEnd)
If blRet = True Then
Me.txtBeginDate.Value = DateStart
Me.txtEndDate.Value = DateEnd
Else
' Add any message here if you want to
' inform the user that no date was selected
Me.txtBeginDate.Value = Null
Me.txtEndDate.Value = Null
End If
End Sub
- Compile the code and save the form.
- Now open the form in regular view and click the command button. The calendar should
then appear.
**Important Note**
In order to select a range of dates, Single-Click interface must be enabled on the
Calendar Properties List.
Click where it says Properties on the calendar, slide down to the option that says "Single
or Double Click" and then move to the right to select "Single Click to Select Date." It
may also help to display more than one month at a time for this procedure. To do that go
to the Properties button again, slide down to where it says "Viewable Months", and then
move to the right and select the number of months you wish to display.
**
- Now click on a beginning date and hold down the mouse button. Slide the mouse over to
whatever ending date you desire and the selected dates will be highlighted as you move.
Let go of the mouse, the calendar will disappear, and the text boxes will fill in with the
respective dates. Pinch yourself, it's not a dream. Lift your chin off the keyboard before
it starts hitting some keys.
11. Stephen has hard coded a maximum date range limit of 31 days. There may be an easier
way to do this (and please let me know if there is Stephen), but you can change this by
modifying one line in his class code.
**Warning-Tread carefully here**
- Open the clsMonthCal in Design View.
- Go up to on the toolbar and select Edit--Find.
- Copy/paste this text in the box that says "Find What": m_MaxSelectRangeofDays = 31
- Make sure "Current Module" is selected and then hit the button that says "Find Next."
- The editor should take you right to the line we need to change.
- Just enter a new number in place of 31.
- Compile the code and save the module changes.
- Go back to your form and do a date range again. You should now be able to select a range
of dates matching your criteria.
12. The really great thing about the calendar (besides the fact that is totally API driven
and therefore no versioning problems like ActiveX Controls) is that it can be customized
to the user's desires via the Preferences options. Each user can choose what options they
wish to use to suit their own likes/dislikes. Try out each of the options in the
Properties list to see what difference it makes to the calendar. You can choose how many
months to view, show week numbers, select different fonts and colors, you can show and
circle the current day for quick retrieval, specify the location where the calendar will
appear, and finally choose between double-clicking a date or single clicking a date. And
the developer doesn't have to do any additional coding. Simply beautiful isn't it?
.........I need a moment.............sniff..........Ok I'm fine now.
That should do it (I think).
Good luck and have fun with it!
Jeff Conrad
Access Junkie
Bend, Oregon