9 Replies - 3156 Views - Last Post: 10 February 2013 - 10:13 AM Rate Topic: -----

#1 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 02:47 AM

Hello Guys,,

I need Your Help I want to save my data in listview to my DB and This is My code to save data in listview
Private Sub save()
ListView1.ListItems.Add , , lblrp.Caption
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtCode.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Caption
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbldate.Caption
End Sub


and this my code to Save Data in MSAccess Using Listview
Private Sub savetodailyrecord()
On Error Resume Next
Dim str As String

str = "INSERT INTO Dailyrecord Values('" & ListView1.SelectedItem.Text & "', '" & ListView1.SelectedItem.SubItems(1) & "', '" & ListView1.SelectedItem.SubItems(2) & "', '" & ListView1.SelectedItem.SubItems(3) & "', '" & ListView1.SelectedItem.SubItems(4) & "', '" & ListView1.SelectedItem.SubItems(5) & "', '" & ListView1.SelectedItem.SubItems(6) & "')"
acd.Execute str
Call Purchase
ListView1.ListItems.clear

End Sub



there's no data save in my DB when i Save ..

Help Me Guys..
thanks in Adavance

Is This A Good Question/Topic? 0
  • +

Replies To: Save Data in MSAccess Using Listview in Vb 6.0

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,666
  • Joined: 12-December 12

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 03:51 AM

The first thing you should do is to remove this line:

On Error Resume Next

This should rarely be used, particularly with database statements!, and you need to see all error messages in order to debug properly.

BTW
Use proper casing (SaveToDailyRecord) and indentation (although, perhaps the indentation was removed when you posted your code).
Was This Post Helpful? 0
  • +
  • -

#3 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 04:47 AM

Thanks...

Only First row of listview only save in DB the rest are not.. What sould i Do?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,666
  • Joined: 12-December 12

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 04:56 AM

You will need to loop through all the listitems. Here's an example I found:

Dim conDataConnection As Connection
Dim strSQL As String
Dim lstSel As ListItem

  Set conDataConnection = New Connection
  conDataConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & _
                         "\Overtime.mdb;Persist Security Info=False"

For Each lstSel In ListView1.LisItems
  strSQL = "Insert Into Overtime (EmployeeName, NextStringFieldName, NumericFieldName) Values (" & _
           "'" & lstSel.Text & "', " & _
           "'" & lstSel.SubItems(1) & "', " & _
           lstSel.SubItems(2) & ")"
  conDataConnection.Execute strSQL
Next
  conDataConnection.Close
  Set conDataConnection = Nothing

This post has been edited by andrewsw: 09 February 2013 - 04:56 AM

Was This Post Helpful? 0
  • +
  • -

#5 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 08:44 AM

Dim lstSel As ListItem
Dim str As String

For Each lstSel In ListView1.ListItems

str = "Insert Into Dailyrecord Values ('" & lstSel.Text & "', '" & lstSel.SubItems(1) & "','" & lstSel.SubItems(2) & "','" & lstSel.SubItems(3) & "','" & lstSel.SubItems(4) & "','" & lstSel.SubItems(5) & "','" & lstSel.SubItems(6) & "')"
acd.Execute str

Next


Call Purchase
ListView1.ListItems.clear




hello sir here's my code but i got a wrong,, can you help me to find out what kind of my code is wrong.. when i run my program and save the data VB 6.0 say: Syntax Error missing operator in query expression

help me sir

still first row in my listview save in DB what shoul i do?

This post has been edited by Jovel Mark: 09 February 2013 - 08:53 AM

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,666
  • Joined: 12-December 12

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 09:10 AM

A syntax error in the query expression usually means you have a mis-placed comma, bracket or space (etc.) Print out str each time within the loop so that you can check it.

Do any of the values you are trying to save contain apostrophes?

This post has been edited by andrewsw: 09 February 2013 - 09:13 AM

Was This Post Helpful? 0
  • +
  • -

#7 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 09:39 AM

View Postandrewsw, on 09 February 2013 - 09:10 AM, said:

A syntax error in the query expression usually means you have a mis-placed comma, bracket or space (etc.) Print out str each time within the loop so that you can check it.

Do any of the values you are trying to save contain apostrophes?


Sir Im new in VB 6.0 I dont know how to do that.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,666
  • Joined: 12-December 12

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 09:45 AM

View PostJovel Mark, on 09 February 2013 - 09:39 AM, said:

View Postandrewsw, on 09 February 2013 - 09:10 AM, said:

A syntax error in the query expression usually means you have a mis-placed comma, bracket or space (etc.) Print out str each time within the loop so that you can check it.


Sir Im new in VB 6.0 I dont know how to do that.

Well if you don't know how to do this then you should take the time to study the fundamentals of VB6. There are plenty of tutorials, possibly some on this site, and books.
Was This Post Helpful? 0
  • +
  • -

#9 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 09 February 2013 - 10:01 AM

thanks Sir..
Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: Save Data in MSAccess Using Listview in Vb 6.0

Posted 10 February 2013 - 10:13 AM

Andrew is of course right, but if you put Debug.Print str and then view the Immediate window, you will find that the value of str is printed there. Also, learn how to use Breakpoints, it's very important. You can google it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1