Hello,
i try to write some data via VBA-Excel-Module in an Access-DB. Unfortunately is there an error in my VBA code and im not able to fix it.
(
My method looks as follows:
Private Sub CommandButton2_Click()
Dim DBFullName As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Cells.Clear
' Database information
DBFullName = ThisWorkbook.Path & "\PMO.mdb"
' Open the connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct
' Create RecordSet
Set Recordset = New ADODB.Recordset
Recordset.Open Source:="Tasks", ActiveConnection:=Connection
With Recordset
.AddNew
.Fields("ParentTask").Value = "C00T35"
.Fields("TaskID").Value = "RA-34-2345"
.Fields("Task").Value = "Maintenance"
.Fields("Org").Value = "Maintenance Team"
.Fields("TeamMember").Value = "John Hutch"
.Fields("StartDate").Value = "21.02.2009"
.Fields("DueDate").Value = "01.04.2009"
'add data for the other fields here
.Update
.Close
End With
End Sub
When I execute this code I get the following error:
Run-time error '2147217900 (80040e14)
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
In Debug Mode it stops at the following code line:
Recordset.Open Source:="Tasks", ActiveConnection:=Connection
I have tried for so long to fix the problem but I do not get it.
Has anybody an idea how the code should look like to execute correctly? :-/
matti
i try to write some data via VBA-Excel-Module in an Access-DB. Unfortunately is there an error in my VBA code and im not able to fix it.
My method looks as follows:
Private Sub CommandButton2_Click()
Dim DBFullName As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Cells.Clear
' Database information
DBFullName = ThisWorkbook.Path & "\PMO.mdb"
' Open the connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct
' Create RecordSet
Set Recordset = New ADODB.Recordset
Recordset.Open Source:="Tasks", ActiveConnection:=Connection
With Recordset
.AddNew
.Fields("ParentTask").Value = "C00T35"
.Fields("TaskID").Value = "RA-34-2345"
.Fields("Task").Value = "Maintenance"
.Fields("Org").Value = "Maintenance Team"
.Fields("TeamMember").Value = "John Hutch"
.Fields("StartDate").Value = "21.02.2009"
.Fields("DueDate").Value = "01.04.2009"
'add data for the other fields here
.Update
.Close
End With
End Sub
When I execute this code I get the following error:
Run-time error '2147217900 (80040e14)
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
In Debug Mode it stops at the following code line:
Recordset.Open Source:="Tasks", ActiveConnection:=Connection
I have tried for so long to fix the problem but I do not get it.
Has anybody an idea how the code should look like to execute correctly? :-/
matti