L
Little Penny
I trying to get the below code that I found at the following link:
http://vbadud.blogspot.com/search/label/Programmatically update Database tables
I'm looking to use a macro via excel to update\edit a record in an
access table. The code below should select the table named
"tbl_Sample" and update the record with a UniqueID of 5 and change the
JobName field to "Success"
Lots of Problem.
Here are the errors I get.
1. Provider cannot be found it may not be properly installed
2. Requested operation requires an OLE DB Session object, which
is not supported by the current provider
3. The connection cannot be used to perform this operation. It is
either closed or invalid in this context
I'm looking for help to get the thing to work.
Thanks Little Penny
My Code:
Sub SampleUpdate()
Dim cn As ADODB.Connection '* Connection String
Dim oCm As ADODB.Command '* Command Object
Dim uID As Long
Dim nJN As String
Dim iRecAffected As Integer
On Error GoTo ADO_ERROR
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Sample\SampleData.mdb;Persist Security Info=False"
cn.ConnectionTimeout = 40
cn.Open
uID = 5
nJN = 12345
Set oCm = New ADODB.Command
oCm.ActiveConnection = cn
oCm.CommandText = "Update tbl_StreamLine Set JobName = 'Test' Where
ID= '5'"
oCm.CommandText = "Update tbl_Sample Set JobNumber ='" & nJN & "'
where UniqueID='" & uID & "'"
oCm.Execute iRecAffected
If iRecAffected = 0 Then
MsgBox "No records inserted"
End If
If cn.State <> adStateClosed Then
cn.Close
End If
Application.StatusBar = False
If Not oCm Is Nothing Then Set oCm = Nothing
If Not cn Is Nothing Then Set cn = Nothing
ADO_ERROR:
If Err <> 0 Then
'Debug.Assert Err = 0
MsgBox Err.Description
Err.Clear
Resume Next
End If
End Sub
http://vbadud.blogspot.com/search/label/Programmatically update Database tables
I'm looking to use a macro via excel to update\edit a record in an
access table. The code below should select the table named
"tbl_Sample" and update the record with a UniqueID of 5 and change the
JobName field to "Success"
Lots of Problem.
Here are the errors I get.
1. Provider cannot be found it may not be properly installed
2. Requested operation requires an OLE DB Session object, which
is not supported by the current provider
3. The connection cannot be used to perform this operation. It is
either closed or invalid in this context
I'm looking for help to get the thing to work.
Thanks Little Penny
My Code:
Sub SampleUpdate()
Dim cn As ADODB.Connection '* Connection String
Dim oCm As ADODB.Command '* Command Object
Dim uID As Long
Dim nJN As String
Dim iRecAffected As Integer
On Error GoTo ADO_ERROR
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Sample\SampleData.mdb;Persist Security Info=False"
cn.ConnectionTimeout = 40
cn.Open
uID = 5
nJN = 12345
Set oCm = New ADODB.Command
oCm.ActiveConnection = cn
oCm.CommandText = "Update tbl_StreamLine Set JobName = 'Test' Where
ID= '5'"
oCm.CommandText = "Update tbl_Sample Set JobNumber ='" & nJN & "'
where UniqueID='" & uID & "'"
oCm.Execute iRecAffected
If iRecAffected = 0 Then
MsgBox "No records inserted"
End If
If cn.State <> adStateClosed Then
cn.Close
End If
Application.StatusBar = False
If Not oCm Is Nothing Then Set oCm = Nothing
If Not cn Is Nothing Then Set cn = Nothing
ADO_ERROR:
If Err <> 0 Then
'Debug.Assert Err = 0
MsgBox Err.Description
Err.Clear
Resume Next
End If
End Sub