Here is the scenario :
I have the follwoing sales return from in my software:
In the from I have tow listview control, the left is Listview and the right is Listview1. I have the following code in procedure :
Dim xsprice As String Dim xsprice1 As String Dim xsquantity As String Dim xcode As String Dim xprofit As String Dim xprofit1 As String Dim xtotalonhand As String Dim xtotalreturn As String Dim xdiscount As String Dim xsinvno As String Dim xsinvdt As String Dim xremark As String Dim xreturnprice As String Dim lvwItem As ListItem Dim mylist As Integer Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim rs1 As ADODB.Recordset With ListView For Each lvwItem In ListView.ListItems lvwItem.SubItems(1) = xsquantity 'lvwItem.SubItems(2) = xsprice Next lvwItem With ListView1 For Each lvwItem In ListView1.ListItems lvwItem.Text = xcode lvwItem.SubItems(1) = xtotalreturn lvwItem.SubItems(2) = xreturnprice Next lvwItem Set cn = New ADODB.Connection cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\main.mdb;Persist Security Info=False" cn.Open Set rs = New ADODB.Recordset rs.Open ("SELECT * FROM tblstock WHERE code = '" & xcode & "'"), con, adOpenDynamic, adLockOptimistic xtotalonhand = rs!on_hand rs!on_hand = Val(xtotalreturn) + Val(xtotalonhand) rs1.Open ("SELECT * FROM tblsales WHERE code = '" & xcode & "'"), con, adOpenDynamic, adLockOptimistic xprofit = rs1!profit xprofit1 = (Val(xprofit) / Val(xsquantity)) * (Val(xsquantity) - Val(xtotalreturn)) xsprice = rs1!sprice xsprice1 = Val(xsprice) - Val(xreturnprice) rs1!profit = xprofit1 rs1!sprice = xsprice1 rs1.Update rs.Update End With End With
I have two tables in my Access database, tblstock and tblsales. what I am trying to do here is, if a customer return a certain purchased product of a certain invoice no.the two tables will be updated e.g. in tblstock the on_hand field will be added with the pcs of product returend and in tblsales. two fields, sprice and profit will be calculated as per the string.
Now when I run the code, I have a type mismatch error in the follwing line :
For Each lvwItem In ListView.ListItems
My question is, Is my coding is right and why the error is coming ?
Plz respond. Thanks in advance
Edited 3 Years Ago by silversurf