Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleDisplay weekly database data with the calendar control
DescriptionThis example shows how to display weekly database data with the calendar control in Visual Basic 6.
Keywordscalendar, weekly, database
CategoriesControls, Database
 
This propgram uses DAO objects to fetch the data. When the user clicks a date on the Calendar control, its Click event handler stores the selected date and the Saturday and Sunday of that date's week. It then calls subroutine ShowData to display the data for that week.
 
Private Sub Calendar1_Click()
Dim selected_date As Date

    selected_date = Calendar1.Value
    dateSunday = DateAdd("d", -(Weekday(selected_date) - _
        1), selected_date)
    dateSaturday = DateAdd("d", 6, dateSunday)

    ShowData
End Sub
 
Subroutine ShowData composes a query to fetch data for the correct week and then executces it.
 
' Show the data.
Private Sub ShowData()
Dim rsWeekInfo As Recordset
Dim query As String
Dim i As Integer

    query = "SELECT * FROM Races " & _
        "WHERE RaceDate >= #" & _
        Format$(dateSunday) & _
        "# AND RaceDate <= #" & _
        Format$(dateSaturday) & _
        "# ORDER BY RaceDate"
    Set rsWeekInfo = dbRaces.OpenRecordset( _
        query, dbOpenSnapshot)

    For i = 0 To 6
        lblRaceDate(i).Caption = _
            Format$(DateAdd("d", i, dateSunday))
        txt1st(i).Text = ""
        txt2nd(i).Text = ""
        txt3rd(i).Text = ""
    Next i

    With rsWeekInfo
        ' Do nothing if no records are selected.
        If .EOF And .BOF Then Exit Sub
        
        .MoveLast
        .MoveFirst
        Do While Not .EOF
            i = DateDiff("d", dateSunday, _
                rsWeekInfo!RaceDate)
            lblRaceDate(i).Caption = !RaceDate
            txt1st(i).Text = !Place1
            txt2nd(i).Text = !Place2
            txt3rd(i).Text = !Place3
            .MoveNext
        Loop
    End With
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated