how to use Stephen Lebans Calendar in 'reverse'?

CraigDolphin

GrumpyOldMan in Training
Local time
Today, 15:50
Joined
Dec 21, 2005
Messages
1,582
Hi.

I've downloaded Stephen Leban's nifty calendar and have it working beautifully to enter in dates and ranges of dates to a fishing schedule table (this is a fishing regulations database). (thanks to RuralGuy for posting the link to this, and other calendars, on another thread)

I have a form for entering some parameters to narrow the results of a select query that shows the start and end dates for individual blocks of consecutive time for each scheduled fishery. (Some fisheries might be scheduled to occur every thursday and friday for a couple of months, or other hard-to-predict ranges of time.)

What I would like to do next is to click a button on the form to make the calendar appear with all the dates where fishing is scheduled to occur (from the query results) be highlighted, or circled (or something equivalent).

My vba 'skills' are not up to tinkering with his class module without some serious assistance. Has anyone tried something similar to this with his calendar? Is it even possible?

I have seen other calendars that do something similar (though I'm still in over my head trying to figure out the modules) but I'd really like to keep with Stephen Leban's calendar since it allows much more felxibility in displaying over various time intervals.

I would greatly appreciate any assistance. Thanks.
 
Well. After tearing out my hair for a couple of days, and a gleaning of wisdom from some old posts on other forums, I have figured this out finally.

In case anyone else wants to do something similar in the future here's how I did it.

I have a query (qGear-dates) with two fields that represent the start date (Sdate) and end date (Enddate) of time periods. Each record represents a time period with consecutive days fished. Consequently, any break in the timeline requires a new record.

I then used the following code in the on click event of my form's command button (getcal):
Code:
Dim db As DAO.Database
Dim myq As DAO.Recordset

Private Sub getcal_Click()
Dim current_val As Date

Set db = CurrentDb()
Set myq = db.OpenRecordset("qGear-dates") ' open a recordset using the results of a query


If Not myq.EOF Then myq.MoveFirst 'goto the first record in the recordset (if there are any records at all)
mc.ResetBoldDayState True 'reset all dates to clear bolded states from earlier searches. Requires addition to clsMonthCal module
Do While Not myq.EOF 'do the following for the currently selected record unless there are no more records in the recordset
    current_val = myq!SDate 'set the current_val variable to the date value of the SDate field of the current record
    Do While current_val <= myq!Enddate 'do the following as long as the current_val date is not after the Enddate field value
        mc.SetBoldDayState DatePart("YYYY", current_val), DatePart("m", current_val), DatePart("d", current_val) 'make the date represented by the current_val variable bold in the calendar
        current_val = current_val + 1 'increment the date by one
    Loop 'go back and repeat the process for each date up to (and including) the enddate of the currently selected record
    myq.MoveNext 'once the end date of this record has been passed, move to the next record in the recordset
Loop 'go back and start the process over for each new record in the recordset

Dim blRet As Boolean
Dim dtStart As Date, dtEnd As Date

dtStart = Nz(Me.picker, 0)
dtEnd = 0

blRet = ShowMonthCalendar(mc, dtStart, dtEnd)

End Sub

to allow you to reset the bold state property you need to add a new sub to the clsMonthCal module.
Code:
Public Sub ResetBoldDayState(reset As Boolean)
If reset Then
Erase BoldDayStates
End If
End Sub

Stephen Leban wrote the add-on to the module which I found on another forum. The rest is my own. Perhaps there's a better way but this is what worked for me.:)

Cheers!
 

Users who are viewing this thread

Back
Top Bottom