I have dtpker1 and dtpker2 to choose from the date and I want to display in Listview. the problem with this code is that it cannot display dates from the listview.
Please help me with the right syntax plzzzzzzzz.........:)
Thank you so much!!
Option Explicit
Dim rs As New Recordset
Dim sum As Double
Dim alert As String
Private Sub cmdDisplay_Click()
If Val(Me.Datefrom.Month) < Val(Me.Dateto.Month) Then
alert = MsgBox("Invalid Date Range. Begining range should be earlier than end range.", vbOKOnly + vbInformation, "Invalid Date")
Else
If Val(Me.Dateto.Day) > Val(Me.Datefrom.Day) Then
alert = MsgBox("Invalid Date Range. Begining range should be earlier than end range.", vbOKOnly + vbInformation, "Invalid Date")
Me.Dateto.Value = Date
Else
End If
End If
Me.lvList.ListItems.Clear
Set rs = New ADODB.Recordset
With rs
.Open "select * from tbl_planted where Date_Projectedharvest between '" & (Datefrom.Value) & "' And '" & (Dateto.Value) & "'", myCn, 1, 2
While Not .EOF
lvList.ListItems.Add , "Key" & rs("Account_No"), rs("Account_No")
lvList.ListItems("Key" & rs("Account_No")).SubItems(1) = rs("Lastname")
lvList.ListItems("Key" & rs("Account_No")).SubItems(2) = rs("Firstname")
lvList.ListItems("Key" & rs("Account_No")).SubItems(3) = rs("MI")
lvList.ListItems("Key" & rs("Account_No")).SubItems(4) = rs("Area")
lvList.ListItems("Key" & rs("Account_No")).SubItems(5) = rs("Date_Planted")
lvList.ListItems("Key" & rs("Account_No")).SubItems(6) = rs("Date_Projectedharvest")
lvList.ListItems("Key" & rs("Account_No")).SubItems(7) = rs("Inspector1")
lvList.ListItems("Key" & rs("Account_No")).SubItems(8) = rs("Inspector2")
.MoveNext
Wend
End With
Dim sql As String
Dim X
sum = 0
For X = 1 To lvList.ListItems.Count
sum = sum + CDbl(lvList.ListItems.Item(X).SubItems(4))
Next X
Me.lblTotalareaplanted.Caption = "Total Area Planted: " & sum
End Sub
Private Sub Form_Load()
Me.Datefrom.Value = Now
Me.Dateto.Value = Now
Set rs = New adodb.Recordset
rs.Open "select * from tbl_planted", myCn, 1, 2
While Not rs.EOF
lvList.ListItems.Add , "Key" & rs("Account_No"), rs("Account_No")
lvList.ListItems("Key" & rs("Account_No")).SubItems(1) = rs("Lastname")
lvList.ListItems("Key" & rs("Account_No")).SubItems(2) = rs("Firstname")
lvList.ListItems("Key" & rs("Account_No")).SubItems(3) = rs("MI")
lvList.ListItems("Key" & rs("Account_No")).SubItems(4) = rs("Area")
lvList.ListItems("Key" & rs("Account_No")).SubItems(5) = rs("Date_Planted")
lvList.ListItems("Key" & rs("Account_No")).SubItems(6) = rs("Date_Projectedharvest")
lvList.ListItems("Key" & rs("Account_No")).SubItems(7) = rs("Inspector1")
lvList.ListItems("Key" & rs("Account_No")).SubItems(8) = rs("Inspector2")
rs.MoveNext
Wend
Me.lblnumberofapplicants.Caption = "Number of Applicants: " & Me.lvList.ListItems.Count
rs.Close
'add
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
If Button.Index = 1 Then
Unload Me
frmLoadingreportlistofharvest.Show 1
ElseIf Button.Index = 3 Then
MsgBox "Printing", vbInformation
Else
Unload Me
End If
End Sub