title: Inserting data into a database from vb6?
body: <p>i am working on a program that takes some data from a listview object and should among other things insert the data into specific fields in a database. i am using vb6 and a ms access 2003 database. im not entirely sure how to connect to the database in vb6 although i do have this code at the moment</p>
  
  <pre><code>Option Explicit
  Public dbCaseGoods As DAO.Database
  Dim rs As DAO.Recordset
  Dim Barcode() As String
  Dim linenumber As Integer
  Dim strinsert As String
  
  
  
  Private Sub btnDone_Click()
  linenumber = 1
  strinsert = "INSERT INTO Work_Order (PO_Number,CNC_Code,Line_No) VALUES ('" &amp; "PO NUMBER" &amp; "', '" &amp; "CNC CODE" &amp; "', '" &amp; "LINE NUMBER" &amp; "')""
  'strinsert = "INSERT INTO Work_Order (PO_Number,CNC_Code,Line_No) VALUES ('" &amp; ListView1.ListItems(linenumber).Text &amp; "' , '" &amp;     ListView1.ListItems(linenumber).SubItems(1) &amp; "','" &amp;     ListView1.ListItems(linenumber).SubItems(2) &amp; "')""
  Set rs = dbCaseGoods.execute(strinsert, dbfailonerror)
  
  txtbarcode.SetFocus
  End Sub
  
  Private Sub Command1_Click()
  Form2.Show
  End Sub
  
  Private Sub Form_Load()
  Set dbCaseGoods = OpenDatabase("I:\Casegoods\database\Contract_Casegoods.mdb")
  
  ListView1.ColumnHeaders.Add Text:="P.O#", Width:=ListView1.Width / 3
  ListView1.ColumnHeaders.Add Text:="Cnc Code", Width:=ListView1.Width / 3
  ListView1.ColumnHeaders.Add Text:="Line #", Width:=ListView1.Width / 8
  End Sub
  
  
  
  Private Sub txtbarcode_KeyPress(KeyAscii As Integer)
  Dim li As ListItem
  
  
  Barcode = Split(txtbarcode.Text, "-")
  On Error Resume Next
     If KeyAscii = vbKeyReturn Then
     Set li = ListView1.ListItems.Add(, , Barcode(0))
     li.SubItems(1) = Barcode(1)
     li.SubItems(2) = Barcode(2)
     txtbarcode.Text = ""
     Command2.Caption = ListView1.ListItems(1).Text
     Command3.Caption = ListView1.ListItems(1).SubItems(1)
     Command4.Caption = ListView1.ListItems(1).SubItems(2)
  End If
  
  End Sub
  </code></pre>
  
  <p>what i am getting right now when i try to hit the button to insert the one line of data into the database is an error stating <code>Expected function or variable</code> and <code>.Execute</code> is highlighted in <code>Set rs = dbCaseGoods.execute(strinsert, dbfailonerror)</code></p>