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
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 ('" & "PO NUMBER" & "', '" & "CNC CODE" & "', '" & "LINE NUMBER" & "')""
'strinsert = "INSERT INTO Work_Order (PO_Number,CNC_Code,Line_No) VALUES ('" & ListView1.ListItems(linenumber).Text & "' , '" & ListView1.ListItems(linenumber).SubItems(1) & "','" & ListView1.ListItems(linenumber).SubItems(2) & "')""
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
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 Expected function or variable
and .Execute
is highlighted in Set rs = dbCaseGoods.execute(strinsert, dbfailonerror)
An INSERT query does not return records so
Set rs = dbCaseGoods.execute(strinsert, dbfailonerror)
won't work. Just use
dbCaseGoods.Execute strinsert, dbFailOnError
You should also look into using parameter queries instead of "gluing together" SQL statements.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments