Invalid operation. (Error 3219)
I am getting this error when using the insert into statement in VB6.
The data engine is DAO to connect to access2003 database.
I tries the select * statement and that work find.
My question to all is why it’s not inserting new record to the database?
Form
Option Explicit
Private Sub cmdtest_Click()
Call DataOpen ‘************ Call the data base *********************
Dim strSQL, xtest1, xtest2 As String
'Dim rsdb As DAO.Recordset
Dim rsdb As ADODB.Recordset
xtest1 = "this is just a test1"
xtest2 = "test is just a nother test"
'strSQL = "SELECT test1, test2 FROM test"
strSQL = "Insert into test(test1, test2)Values('" & xtest1 & "', '" & xtest2 & "')"
Set rsdb = gdb.OpenRecordset(strSQL)
End Sub
Data MODULE
Option Explicit
Public gdb As Database
'Public gdb As Database
Public gstrDatabase As String
'Public Function DataOpen() As Boolean
Public Function DataOpen() As Integer
gstrDatabase = (App.Path & "\data.mdb")
Set gdb = DBEngine.Workspaces(0).OpenDatabase(gstrDatabase)
DataOpen = True
End Function
I am getting this error when using the insert into statement in VB6.
The data engine is DAO to connect to access2003 database.
I tries the select * statement and that work find.
My question to all is why it’s not inserting new record to the database?
Form
Option Explicit
Private Sub cmdtest_Click()
Call DataOpen ‘************ Call the data base *********************
Dim strSQL, xtest1, xtest2 As String
'Dim rsdb As DAO.Recordset
Dim rsdb As ADODB.Recordset
xtest1 = "this is just a test1"
xtest2 = "test is just a nother test"
'strSQL = "SELECT test1, test2 FROM test"
strSQL = "Insert into test(test1, test2)Values('" & xtest1 & "', '" & xtest2 & "')"
Set rsdb = gdb.OpenRecordset(strSQL)
End Sub
Data MODULE
Option Explicit
Public gdb As Database
'Public gdb As Database
Public gstrDatabase As String
'Public Function DataOpen() As Boolean
Public Function DataOpen() As Integer
gstrDatabase = (App.Path & "\data.mdb")
Set gdb = DBEngine.Workspaces(0).OpenDatabase(gstrDatabase)
DataOpen = True
End Function