Results 1 to 15 of 15

Thread: [resolved]Calendar Control problem

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    55

    [resolved]Calendar Control problem

    I have a form with a microsoft calendar control 9.0 and a flexgrid.
    When the user changes the date I want it to clear the flexgrid.

    It clears when you click a certain day, but if you change the month or year without a day selected it does not clear.

    I have used the click, afterupdate, beforeupdate, newmonth,newyear events of the control. None of them will clear without a day selected.

    What can I do?
    Last edited by RyanW; Sep 12th, 2002 at 04:17 PM.

  2. #2
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    I have checked Microsoft calendar 8.0 and the only events whichs work when you chanfe the month or the year are NewMonth and NewYear respectively.

    The only problem I have founs is that if you check for the month for example on NewMonth it will return 0 until you select a day.

    If you post the code you use to clear the grid, some more help can be provided

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Here's a brief exasmple of what you may need...
    Attached Files Attached Files
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    55
    I use Flexgrid.clear to clear the grid.

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by RyanW
    I use Flexgrid.clear to clear the grid.
    You can use that in the

    VB Code:
    1. Private Sub Calendar1_NewMonth()
    2.  
    3. ' and
    4.  
    5. Private Sub Calendar1_NewYear()
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    55
    Ok here is the full code. I have this in the click event of the calendar control.

    Code:
    MSFlexGrid1.Clear
    MSFlexGrid1.TextMatrix(0, 0) = "TIME"
    strResource = "Select * from ResSched where " & _
                  "[Date] = #" & Calendar1.Value & "#"
    Dim theTime As Variant
    theTime = TimeValue("8:00")
    Dim incrementVal As Integer
    Dim index As Integer
    If cmbInterval.Text = "10" Then
                incrementVal = 10
                For index = 1 To 55
                    MSFlexGrid1.Rows = index + 1
                    MSFlexGrid1.TextMatrix(index, 0) = theTime
                    'Increment theTime
                    theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
                Next
            ElseIf cmbInterval.Text = "15" Then
                incrementVal = 15
                For index = 1 To 37
                    MSFlexGrid1.Rows = index + 1
                    MSFlexGrid1.TextMatrix(index, 0) = theTime
                    'Increment theTime
                    theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
                Next
            ElseIf cmbInterval.Text = "20" Then
                incrementVal = 20
                For index = 1 To 28
                    MSFlexGrid1.Rows = index + 1
                    MSFlexGrid1.TextMatrix(index, 0) = theTime
                    'Increment theTime
                    theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
                Next
            ElseIf cmbInterval.Text = "30" Then
                incrementVal = 30
                For index = 1 To 20
                    MSFlexGrid1.Rows = index + 1
                    MSFlexGrid1.TextMatrix(index, 0) = theTime
                    'Increment theTime
                    theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
                Next
            ElseIf cmbInterval.Text = "60" Then
                incrementVal = 60
                For index = 1 To 10
                    MSFlexGrid1.Rows = index + 1
                    MSFlexGrid1.TextMatrix(index, 0) = theTime
                    'Increment theTime
                    theTime = TimeSerial(Hour(theTime), Minute(theTime) + incrementVal, Second(theTime))
                Next
            End If
           Set rsHeader = New Recordset
    
    With rsHeader
            .Open strResource, madocon, adOpenDynamic, adLockOptimistic, adCmdText
            count1 = 1
            Do While count1 <> MSFlexGrid1.Cols
                MSFlexGrid1.ColWidth(count1) = 2000
                count1 = count1 + 1
            Loop
    
            count1 = 1
            Do While .EOF = False
                If count1 > 10 Then
                    MSFlexGrid1.Cols = count1 + 1
                End If
                MSFlexGrid1.TextMatrix(0, count1) = !RName
                count1 = count1 + 1
                rsHeader.MoveNext
            Loop
    
    End With
    rsHeader.Close
    Set rsHeader = Nothing
    
    
    strPopulate = "Select * From Appointment Where" & _
    "[AppDate] = #" & Calendar1.Value & "#"
    Set rsPopulate = New Recordset
    With rsPopulate
            .Open strPopulate, madocon, adOpenDynamic, adLockOptimistic, adCmdText
    
            If .EOF = True Then
                Exit Sub
            Else
                rsPopulate.MoveFirst
                Do While .EOF = False
    
    
                MSFlexGrid1.TextMatrix(!TID, !AIdNum) = !AFName
                rsPopulate.MoveNext
    
            Loop
            End If
    End With
    rsPopulate.Close
    Set rsPopulate = Nothing

    The problem is the calendar controls value does not change unless you click a day.

  7. #7
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    You can put your code in a procedure and call it from Click, Newmonth and newyear events

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Well

    VB Code:
    1. Private Sub Calendar1_NewMonth()
    2.  
    3. Me.MsFlexGrid1.Clear
    4.  
    5. End Sub
    6.  
    7. Private Sub Calendar1_NewYear()
    8.  
    9. Me.MsFlexGrid1.Clear
    10.  
    11. End Sub
    12.  
    13. Private Sub Calendar1_Click()
    14.    
    15. ' CALLYOURCODEHERE (The Date Has Been Changed !!!)
    16.    
    17. End Sub
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    55
    Thanks I knew you wre going to say that because as you were I was testing the same thing. And it works

    Isn't it funny sometimes how the simplest things boggle you sometimes.

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by RyanW
    Thanks I knew you wre going to say that because as you were I was testing the same thing. And it works

    Isn't it funny sometimes how the simplest things boggle you sometimes.
    It's all a part of a day's work. Glad you got it to work...

    Remember, add resolved to you first post subject line...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    55
    One more problem when I change the month and do not click a day and then go back to the previous month the flexgrid is cleared. It doesn't reload until I click a day.

  12. #12
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Not sure how you should handle that. The date is always the same, unless user clicks on the calendar. If this is that much of an issue, why not use the DTPicker control? It has a mini-dropdown calendar of it's own...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  13. #13

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    55
    It is not that big of an issue. I will probably just leave it.

  14. #14
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    After a NewMonth or a NewYear event, the variables Calendar1.Day, Calendar1.Month and Calendar1.Year remain at zero until the day changes.

    the following example shows a little trick to update the date after the events

    VB Code:
    1. Dim tempDay As Integer
    2.  
    3. Private Sub Calendar1_Click()
    4. tempDay = Calendar1.Day
    5. End Sub
    6.  
    7.  
    8. Private Sub Calendar1_NewMonth()
    9. Calendar1.Day = tempDay + 1
    10. Calendar1.Day = tempDay
    11. Text1.Text = Calendar1.Value
    12. End Sub
    13.  
    14.  
    15. Private Sub Calendar1_NewYear()
    16. Calendar1.Day = tempDay + 1
    17. Calendar1.Day = tempDay
    18. Text1.Text = Calendar1.Value
    19. End Sub
    20.  
    21. Private Sub Form_Load()
    22. tempDay = Calendar1.Day
    23. End Sub

    Hope you can use it in your application

  15. #15
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    If you interested furthur you could add more code into your newmonth and newyear events to select the date based off that month (you'd have to check if the new month had the same number of days as the old month for this to be effective)...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width