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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force Moday start start date no matter what is selected in calendar Wk 1

Status
Not open for further replies.

act2

Technical User
Dec 17, 2005
34
US
I have a combo box which activates the Calendar Control 9.0. I want to be able to change whatever date someone may select in the calendar control to the Monday date for that week. Tried using the Weekday function with out any luck. Any suggestions. Thanks
 
This may help:
Need help creating automated monday dates
thread702-1102158
 
This seemed to work, but I did not try a lot of different approaches.

Private Sub ActiveXCtl11_Exit(Cancel As Integer)
'Monday is a value of 2
Do Until WeekDay(ActiveXCtl11.Value) = 2
ActiveXCtl11.Value = ActiveXCtl11.Value - 1
Loop
End Sub
 
If you go with my logic, you may want to play with some different events. The on exit event does not change the value until you leave the control. This seemed to work better.

Private Sub ActiveXCtl11_Click()
Me.Recalc
Do Until WeekDay(ActiveXCtl11.Value) = 2
ActiveXCtl11.Value = ActiveXCtl11.Value - 1
Loop
Me.dateCurrentTour.Requery
End Sub
 
The guts of Gol4's suggestion (thread shown above) is:
[tt]dteDate = Date
dteMonday = dteDate - (Weekday(dteDate) + 5)[/tt]
However, some note must be taken of the day that the week starts on.
 
MajP, Thanks for your help, your code worked great. Here is how I used it. Thanks again

Code:
Dim cboOriginator2 As ComboBox




Private Sub ocxCalendar2_Click()

' Copy chosen date from calendar to originating combo box



 Me.Recalc
 Do Until Weekday(ocxCalendar2.Value) = 2
    ocxCalendar2.Value = ocxCalendar2.Value - 1
 Loop
 


    cboOriginator2.Value = ocxCalendar2.Value
' Return the focus to the combo box and hide the calendar and
    cboOriginator2.SetFocus
    ocxCalendar2.Visible = False
    Set cboOriginator2 = Nothing
End Sub



Private Sub StartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator2 = StartDate
' Unhide the calendar and give it the focus
    ocxCalendar2.Visible = True
    ocxCalendar2.SetFocus
 
' Match calendar date to existing date if present or today's date
    If Not IsNull(StartDate) Then
     ocxCalendar2.Value = cboOriginator2.Value
    Else
        ocxCalendar2.Value = Date
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top