Calendar default value (1 Viewer)

chthomas

Registered User.
Local time
Today, 06:37
Joined
Feb 8, 2000
Messages
32
I have a form where there is a date field. When the user double clicks on the date field, a calendar pops up. This is working fine. Now my problem. I should restrict the user to select only the last day of any month (Am using dsum expression for calculating running totals between 2 dates). How can i accompolish this.

Am using the following module for calendar

Function PopupCalendar(ctl As Control) As Variant
'
' This is the public entry point.
' If the passed in date is Null (as it will be if someone just
' opens the Calendar form raw), start on the current day.
' Otherwise, start with the date that is passed in.
'
Dim frmCal As Form
Dim varStartDate As Variant

varStartDate = IIf(IsNull(ctl.value), DATE, ctl.value)
DoCmd.OpenForm CALENDAR_FORM, , , , , A_DIALOG, varStartDate

' You won't get here until the form is closed or hidden.
'
' If the form is still loaded, then get the final chosen date
' from the form. If it isn't, return Null.
'
If isFormLoaded(CALENDAR_FORM) Then
Set frmCal = Forms(CALENDAR_FORM)
ctl.value = Format(DateSerial(frmCal!YEAR, frmCal!Month, frmCal!Day), "dd/mm/yyyy")
DoCmd.Close A_FORM, CALENDAR_FORM
Set frmCal = Nothing
End If
End Function


and for calling am using

=PopupCalendar(Screen.ActiveControl)

or is there any alternate way of doing this, like user selects say month name in an additional field, then this date field is filled with the last day of the selected month automatically.

Am using Access2000.

Regards,

Charley
 

RuralGuy

AWF VIP
Local time
Yesterday, 23:37
Joined
Jul 2, 2005
Messages
13,826
Try: ctl.value = Format(DateSerial(frmCal!YEAR, frmCal!Month+1, 0), "dd/mm/yyyy")
Day 0 of a month is the last day of the previous month.
 

chthomas

Registered User.
Local time
Today, 06:37
Joined
Feb 8, 2000
Messages
32
RuralGuy,

Excellent. You saved my day. Works perfectly.

Thanks a lot

Regards,

Charley
 

RuralGuy

AWF VIP
Local time
Yesterday, 23:37
Joined
Jul 2, 2005
Messages
13,826
You're welcome Charley. Glad I could help.
 

chthomas

Registered User.
Local time
Today, 06:37
Joined
Feb 8, 2000
Messages
32
RuralGuy,

I have an extra requirement now. At any time the calendar has to be limited to next 4 months. ie when the user double clicks it should show only May,Jun,Jul and Aug months. When in May month when the user double clicks it should show only Jun,Jul,Aug and Sep months.

Is it accompolishable, or is there any way an error message can be displayed if the user selects months not in the range?

Regards,

Charley
 

RuralGuy

AWF VIP
Local time
Yesterday, 23:37
Joined
Jul 2, 2005
Messages
13,826
Use the DateDiff() function on the returned date and the date you started with to validate.
 

chthomas

Registered User.
Local time
Today, 06:37
Joined
Feb 8, 2000
Messages
32
Thanks for your help again.

Regards,

Charley
 

RuralGuy

AWF VIP
Local time
Yesterday, 23:37
Joined
Jul 2, 2005
Messages
13,826
You're welcome Charley. Always glad to help.
 

Users who are viewing this thread

Top Bottom