Lebans Holdings 1999 Ltd.

 Home ] Up ] Feedback ] Contents ] Search ] What's New ] Files & Tips ] 

MonthCalendar
Home
Up
Select A Row
Magnify
LimitCharsMemo
RotateText
ImageClass
AutoSize TextBox
ZoomInOut
PaintProgram
FormatByCriteria
CmdButton
SetGetSB
Transparent
AnimatedGifPlayer
LoadJpegGif
ImageControlToClipBoard
CanGrow
LimitTextInput
AutoSizeFont
AnimateForm
AutoUpDown
MonthCalendar
AutoColumnWidth
RichText
SelectAlpha
FormDimensions
LoadSaveJpeg
TabColors
ToolTip
TextWidth-Height
MouseWheelOnOff
AlternateColorDetailSection
ConFormsCurControl
ConditionalFormatting
AutoSizeOLE
ChangeMDIBackGround
RecordNavigationButtons
HTMLEditor
CopyGetRTFfromClipboard
OpenForm
GradientFill

RETIRED! September 2009

I have officially retired from all things Access. Please do not send Email requesting support as I will not respond.

 

Keep all of your questions to the Newsgroups where everyone will benefit!

 

 

New Version 2.05 March 22, 2005

A97MonthCalendar.zip is an A97 database containing a Class that wraps the Microsoft Month Calendar Common Control in an easy to use interface.

A2K Version here: MonthCalendar Access 2000.zip   

This is a completely API generated Month Calendar derived directly from the Common Control DLL.

What this means is that there are no distribution or versioning issues as there are if you use the ActiveX Month Calendar control. In other words this is not an ActiveX control!

Click Here for KeyBoard Navigation Information

Click Here For Version Information

Click Here for Step by Step installation and usage instructions

The image on the left shows the MonthCalendar displaying 4 months. The image on the right shows the Properties Menu in the dropped state.

                                                                                                       

 

Step by Step instructions for how to use the MonthCalendar in your own applications.

Here is a post by fellow Access Developer Jeff Conrad. He has been kind enough to create detailed step by step instructions for the novice Access user.

Hi Dave,

Ok, here are the step-by-step instructions for using 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


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(A2K) 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 with Access versions A2K or A2K2. 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
 

' This declares the MonthCalendar Class
Private mc As clsMonthCal
 


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?

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.

11. Stephen has set a  default value of a maximum date range limit of 31 days. There are two methods to change this value. In the Form's Load event, or before you call the ShowMonthCalendar function you can simply set the MaxSelectRangeOfDays property. Sample code would be like:

mc.MaxSelectRangeOfDays = 365

Alternatively, you can hard code the default value of this property within the Class's Initialize event.

**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?

That should do it (I think).

Good luck and have fun with it!
Jeff Conrad
Access Junkie
Bend, Oregon

 

Navigating within the Month Calendar

Microsoft® Windows® does not support dates prior to 1601. See FILETIME for details.
The month-calendar control is based on the Gregorian calendar, which was introduced in 1753. It will not calculate dates that are consistent with the Julian calendar that was in use prior to 1753.

The Month Calendar Control User Interface
The month calendar control user interface allows the user to select a date from the displayed days or change the control's display in various ways.

Scrolling the control's display
By default, when a user clicks the arrow buttons in the top left or top right of the month calendar control, the control updates its display to show the previous or next month. If the month calendar control is displaying more than one month at a time, the display changes by the number of months currently in view. That is, if the month calendar displays January, February, and March and the user clicks the top right arrow button, the control updates its display to show April, May, and June. The user can also perform the same action by clicking the partial months displayed before the first month and after the last month.

The following keyboard commands can also be used to change the current month.

PAGE UP (VK_NEXT)  Move to the next month. 
PAGE DOWN (
VK_PRIOR)  Move to the previous month. 
HOME (
VK_HOME)  Move to the first day of the current month. 
END (
VK_END)  Move to the last day of the current month. 
CTRL + HOME  Move to the first visible month. 
CTRL + END  Move to the last visible month. 


An application can change the number of months by which the control updates its display by using the MCM_SETMONTHDELTA message or the corresponding macro, MonthCal_SetMonthDelta. However, the PAGE UP and PAGE DOWN keys change the selected month by one, regardless of the number of months displayed or the value set by MCM_SETMONTHDELTA.

Selecting a nonadjacent month
When a user clicks the name of a displayed month, a pop-up menu appears that lists all months within the year. The user can select a month on the list. If the user's selection is not visible, the month calendar control scrolls its display to show the chosen month.

Selecting a different year
If the user clicks the year displayed next to a month name, an up-down control appears in place of the year. The user can change the year with this control. The month calendar control updates its display for the selected year when the up-down control loses focus. The related keyboard commands are:

CTRL + VK_NEXT Move to the next year. 
CTRL + VK_PRIOR Move to the previous year. 

Selecting the current day
If a month calendar control is not using the MCS_NOTODAY style, the user can return to the current day by clicking the "Today" text at the bottom of the control. If the current day is not visible, the control updates its display to show it. Related keyboard commands are:

VK_LEFT Move to the previous day. 
VK_RIGHT.  Move to the next day. 
VK_UP Move to the previous week. 
VK_DOWN Move to the next week. 

 

Version Information

Version 2.05 March 21, 2005

Removed dependency on DAO for custom property settings. Writes to registry instead.

Version 2.03 June 02, 2004

Added support for Keyboard to select a date and close Calendar window with no Mouse interaction. Arrow Keys, PageDown etc. can be used to navigate the dates int he Calendar window. When you have the desired date highlighted press the ENTER key to select this date and close the Calendar window.

Version 2.02 May 23, 2004

Fix bug with Calendar positioning for "Where user last dragged".

Version 2.01 April 12, 2004

Complete rewrite of the Window Enable/Display logic to properly support the calling Form's Modal and Popup properties. Also the new logic now eliminates the window redraw/flashing  issues that were visible in certain versions of Windows. Added error handling in the ShowMonthCalendar function. Finally, brought both the internal and external version numbers together. Barring any bug fixes from code modifications to this version, this is the final production release of the MonthCalendar class. The code is now very stable and in use by thousands of users.

Version 9.8 April 05, 2004

Couple of UI Bug fixes. Both the Font and Color Dialog Windows were appearing BEHIND the MonthCalendar window. If the user did not select a Color, the returned Error value(-1) was being applied.

Version 9.6 April 01, 2004

Sorry, another (and the final) Major modification to the calling function logic including calling Parameter order.  Removed several function params and made them persistent properties instead. Simplified function call to only require 3 params. Added Menu Check marks for current settings in Properties Menu. Added Menu to allow user to close the Calendar Window.

Version 9.4 March 28, 2004

Major modification to the calling function logic including calling Parameter order.  Changed function to return Boolean FALSE and "StartSelectedDate =0"  if user did not select a date from the MonthCalendar.  The hWndForm param is no longer optional.

Version 9.2 January 26, 2003

Fixed issue with focus not returning to forms in Popup mode.

Version 9.1

Fixed DayState property so that it is actually useable now without having to jump through hoops! Fixed Window positioning prop so Calendar will now popup at the cursor location when the user clicks to open the Calendar. Fixed(hopefully) issue of Access properly getting the focus after the Calendar closes. Cleaned code up a bit more!!

Version 8.4

Thanks to Blake Snell for pointing out an issue relating to date selection and closing the MonthCalendar window. This version will not report a changed date of the user merely scrolls through the months. The user must explicitly CLICK and select a date. Also I removed support for double clicking to select a date. I have left the logic in but commented out for those of you that need this functionality. There is still a bug in the method I use to force the calendar to be modal under Win98. Sometimes, if the Internet Explorer window is open, it will pop to the top after a date is selected. This only happens on Win98 and I am having trouble resolving this issue as I cannot duplicate it with certainty.

Version 8.3

Thanks to Korado for the noticing that the Calendar window was not always the top most window with a Form in PopUp mode. Modified window style to force the Calendar window to always stay  on top in the Z order.

Version 8.2

Finally, the Calendar window is MODAL!!! No more crashes under WinNT or higher if the user tries to close the Access app with the Calendar window still open - because they cannot!

Version 7.6

Fixed Win2K/A2K issue with single and double clicking. It's not perfect but it works. Need to account for system time between mouse clicks to allow for value to wrap.

Version 7.4

Hook up the Color props to the Custom Database props to allow for persistence of users color choices for the Calendar .

Version 7.3

The logic I was using to force the Calendar to not close if the Font or Color Dialog windows were open failed under specific circumstances. Certain applications, Outlook Express for example, keep a hidden dialog window open at all times. The result was you could not CLOSE the calendar!  Anyway I have changed the logic to use an internal flag so the Calendar's modal properties work as expected. 

Version 7.2

The Calendar is now Modal! modCalendar is even starting to have its code cleaned up!

Version 6.3

Finally...SetDayState is now supported! You can select which days of each month you wish to have the Calendar render as BOLD. Also added a property to allow the user to select the placement of the Calendar on the screen. Options include Cursor, Manual Drag, Center Access App, Center Screen and Top Left Corner of Screen.

Version 4.2

Added call to UnRegister the custom Window Class. Fixes the GPF generated when modifying the source and then recompiling. There is a related A2K Bug that is fixed as well. The control finally seems to be quite solid and has undergone extensive testing in many environments.

Version 4.0

Add logic to allow Calendar to be manually placed/docked by user. Will add menus and custom properties to store this preference in next release.

Fixed display bug when only 1 month is displayed and left most column is not redrawn properly.

Version 3.9a

Add logic to handle controls with NULL dates sent to calling function. 

Version 3.9

Fixed method of calling Calendar to display Today's date. 

Fixed corruption in Form that showed up intermittently. Decompiled.

Version 3.8

** BUG FIX**  Pressing the SHIFT Key under WIN2K caused a GPF. My partner Pedro Gil found the cause. I had inadvertently left in some debug code that was calling CopyMemory on what is now , under the current logic, a random memory address. Under Win9x you can get away with this but with WIN2K's more advanced memory protection logic you will generate an exception. 

Added parameters to calling function to allow user to pre-select a single date or range of dates, when the Calendar first opens.

Version 3.6

Fixed Double Click bug when scrolling months. Added code to Hit Test on LeftMouseButtonDown to verify where cursor is in Calendar.

Added property to set Single or Double Click to select a date.

Version 3.3

Fixed Double Click and Menu Bug

Added support to allow Calendar to pop up at cursor location. Needs more work as Calendar is redrawn at Screen instead of Client coordinates on subsequent redraws. Also needs to allow WM_Move messages to update XY coordinates for the next time the Calendar is popped up. Code is included but commented out until Screen to Client issue is resolved.

Version 3.2

Added support to return range of dates Selected

Double Click with the Mouse Button will now close the Calendar

Version 3.1

Added support for Keyboard Accelerators

Version 3.0

Complete Rewrite. This Calendar is now Form FREE!

 

 
 

May 23, 2004 Product Update
 
 
Rich Text ActiveX control. Version 1.8

Click Here!

 

Mar 15, 2005 Product Update
 
MouseHook  Replaces the MouseWheel DLL subclassing solution. Turns On/Off the MouseWheel with one line of code. No DLL registration required. Now supports Logitech mice!

Click Here! 

 

 

 
Back ] Home ] Up ] Next ] 
Stephen Lebans Copyright 2009

Last Modified : 09/11/09 12:03 AM