Click here to Skip to main content
15,886,588 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
VB
Private Sub BtnAdd3_Click()
    Set OBJLIST = ListView1.ListItems.Add(, , Text1.Text)
        OBJLIST.SubItems(1) = Text4.Text
        OBJLIST.SubItems(2) = Text3.Text
        OBJLIST.SubItems(3) = Combo2.Text
        OBJLIST.SubItems(4) = Text5.Text
        OBJLIST.SubItems(5) = Text7.Text
        OBJLIST.SubItems(6) = Text8.Text
        OBJLIST.SubItems(7) = Text9.Text
        OBJLIST.SubItems(8) = Text11.Text
End Sub

Private Sub BtnEdit3_Click()
SQL = "SELECT * FROM [NOTE]"
.Open SQL, CON, 1, 2
For i = 1 To ListView1.ListItems.Count
a = "DOC_NO <>" & ListView1.ListItems(i).Text & ListView1.ListItems(i).ListSubItems(1).Text
.Find a, , adSearchForward

SQL = "INSERT INTO [NOTE](DOC_NO,DOC_SUBNO,AID,QTY,RATE,TOTAL_AMNT,DOC_TYPE,DOC_DATE,REMARK,LOC_ID,SUP_ID) " & _
" VALUES(" & ListView1.ListItems(i).Text & ListView1.ListItems(i).ListSubItems(1).Text & "," & ListView1.ListItems(i).ListSubItems(1).Text & "," & _
"" & ListView1.ListItems(i).ListSubItems(2).Text & "," & ListView1.ListItems(i).ListSubItems(5).Text & "," & _
" " & ListView1.ListItems(i).ListSubItems(6).Text & "," & ListView1.ListItems(i).ListSubItems(7).Text & "," & _
" 'DEBIT','" & DTPicker2.Value & "','" & Text2.Text & "'," & _
" " & Combo4.ItemData(Combo4.ListIndex) & "," & Combo5.ItemData(Combo5.ListIndex) & ")"
    Set RS = CON.Execute(SQL)
Next
End If
End Sub

This code adds data from ctrl's to listview but at the last position(after all already shown records in listview)....
When I click save button,it starts saving records from top position(which records are already exist in database)
So I want to save the currently added record present at last position in listview...
datz y I coded for <.find>,it's records in listview n again saves existing rec with different autonumber.......
I want to skip the existing rec n save only those whose doc_no+doc_subno are new....
plz help me....
Posted
Updated 6-May-13 21:48pm
v4

1 solution

If you want to add just the last item of the listview to the database (your question is not clear) then
  • Remove the For loop
  • set i = ListView1.ListItems.Count-1
     
    Share this answer
     
    Comments
    surkhi 7-May-13 5:42am    
    Actually not just the last item but (group of record with same doc_no) multiple items(bcoz one doc_no contains many doc_subno line of items) added to the list already....... so btnsave_click sh'd check all the records and filter the existing n new one n save those new records....
    so this'll not go for that.....
    help me
    surkhi 7-May-13 5:51am    
    Here I'm using BtnAdd() for juz filling listview from textboxes (not saving them to database 1 by 1 but display in listview) n
    BtnEdit/BtnSave() will look into listview n save the newest as a whole record...

    This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



    CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900