Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Control 11 Question

Status
Not open for further replies.

MemphisVBA

Technical User
May 31, 2006
23
US
Is there any way to limit the available choices a user has on the control? For example, in my application, the only valid "start date" is on the 1st or the 15th of each month. Is it possible to disable the other dates?

Also, what if I just want to capture month and year for an expiration date?

Thanks
 
Something like this would work
Code:
Private Sub Calendar2_BeforeUpdate(Cancel As Integer)
 
  If Not (Day(Calendar2.Value) = 1 Or Day(Calendar2.Value) = 15) Then
    MsgBox "StartDate must be on 1 or 15 of the month. Setting Default to 1"
    Calendar2.Value = DateSerial(Year(Calendar2.Value), Month(Calendar2.Value), 1)
  End If
End Sub

However, If you can only choose 2 dates this seems like a wierd user interface. Maybe you want to make your own.

If you only want month and year, I always suggest that you still save it as a date. It is just so much easier to do calculation with dates and times if they are saved as dates. Using dateserial function you can convert a part of a date to a date, and using the Year, Month, and Day functions you can retrieve a part from a date.

So if I had a combobox with years, and another with months, I can convert it to a date

= dateserial(comboYear,comboMonth,1)
 
And if you want the last day of the selected month as expiration date:
DateSerial(comboYear, 1+comboMonth, 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top