This code will sum-up the value of a listview and save the entire list of a listview in just one click.
Dim scon As ADODB.Connection
Dim srec As ADODB.Recordset
Dim slist As ListItem
Dim sum As Double
Private Sub Command2_Click()
Dim sql As String
Dim x
sum = 0
For x = 1 To ListView1.ListItems.Count
sum = sum + CDbl(ListView1.ListItems.Item(x).SubItems(2))
sql = "insert into salary2 (idno,name,salary) values "
sql = sql & "(" & CLng(ListView1.ListItems.Item(x)) & ",'"
sql = sql & ListView1.ListItems.Item(x).SubItems(1) & "',"
sql = sql & CDbl(ListView1.ListItems.Item(x).SubItems(2)) & ")"
scon.Execute sql
Next x
Set slist = ListView1.ListItems.Add(, , " ")
Set slist = ListView1.ListItems.Add(, , "")
slist.SubItems(1) = "Total is==> P"
slist.SubItems(2) = Format(sum, "##,##0.00")
MsgBox "save record"
End Sub
Private Sub Form_Load()
Set scon = New ADODB.Connection
scon.Open "Provider=microsoft.jet.oledb.4.0;" & _
"Data source=" & App.Path & "\sum.mdb"
displayrec
End Sub
Sub displayrec()
Set srec = New ADODB.Recordset
srec.Open "select * from salary", scon, adOpenDynamic, adLockPessimistic
If srec.EOF Then Exit Sub
Do While Not srec.EOF
Set slist = ListView1.ListItems.Add(, , srec(0))
slist.SubItems(1) = srec!Name
slist.SubItems(2) = Format(srec!salary, "##,##0.00")
srec.MoveNext
Loop
End Sub
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment