如何在带有数据库的列表视图中使用 dtpicker 过滤日期

How to filter dates using dtpicker in listview with database

我正在创建一个工资单系统,我想使用dtpicker在listview中搜索日期并计算每日费率的数量,请帮助我

   Private Sub sumBtn_Click()
   Dim objItem As ListItem
   Dim iCounter As Integer
   Dim lngDailyRate As Long

Dim iDateSubitemIndex As Integer
Dim iDailyRateSubitemIndex As Integer

iDateSubitemIndex = 6
iDailyRateSubitemIndex = 7

For iCounter = 1 To Listview1.ListItems.Count

    ' Get List Item
    Set objItem = Listview1.ListItems.Item(iCounter)

    ' Check Date
    If CDate(objItem.SubItems(iDateSubitemIndex)) >= DTPicker3 And CDate(objItem.SubItems(iDateSubitemIndex)) >= DTPicker4 Then
    lngDailyRate = lngDailyRate + CLng(objItem.SubItems(iDailyRateSubitemIndex))

    End If
Next

    MsgBox "Daily Rate for " & DTPicker3 & " to " & DTPicker4 & " is " & 
  lngDailyRate

  End Sub

以下是仅使用 ListView 中的数据总结 DAILY_RATE 列的方法:

Private Sub Command1_Click()
    Dim objItem As ListItem
    Dim iCounter As Integer
    Dim lngDailyRate As Long

    Dim iDateSubitemIndex As Integer
    Dim iDailyRateSubitemIndex As Integer

    ' Update these to reflect your ListView
    iDateSubitemIndex = 1
    iDailyRateSubitemIndex = 2

    For iCounter = 1 To ListView1.ListItems.Count

        ' Get List Item
        Set objItem = ListView1.ListItems.item(iCounter)

        ' Check Date
        If CDate(objItem.SubItems(iDateSubitemIndex)) = DTPicker1 Then
            lngDailyRate = lngDailyRate + CLng(objItem.SubItems(iDailyRateSubitemIndex))
        End If

    Next

    MsgBox "Daily Rate for " & DTPicker1 & " is " & lngDailyRate

End Sub

请更新两个 SubitemIndex 变量以匹配您的 ListView 中的列。这些用于从正确的列中检索数据。