Automation error: Connecting excel with Access

akar

New Member
Joined
Jul 6, 2011
Messages
7
I am trying to export table data from excel2007 to a table with same attributes in access2007. After using the following code in excel-VBA I am getting error - "Run Time Error - '-2147217900(80040e14)': Automation error"

Following is my code:

Private Sub CommandButton1_Click()
Dim cn As ADODB.Connection
Dim oCm As ADODB.Command
Dim SalesRep As String
Dim iRecAffected As Integer
Set cn = New ADODB.Connection
cn.ConnectionString = "DSN=MS Access Database;DBQ=S:\Act\Planning & Reporting\Budgets\Ad-Hoc\Ameya\Forecast_Sales\Forecast Sales.accdb;DefaultDir=S:\Act\Planning & Reporting\Budgets\Ad-Hoc\Ameya\Forecast_Sales;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;"
cn.ConnectionTimeout = 40
cn.Open
SalesRep = "Akar"
Set oCm = New ADODB.Command
oCm.ActiveConnection = cn
oCm.CommandText = "Insert Into Community (Store),values(""&SalesRep&"")"
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


End Sub


System details: Microsoft XP Version 2002 SP3

Any help will be greatly appreciated.

Thanks,
-Akar.
 
Thank you Bob, James and Noorie. I was able to run the program when i converted my database to .mdb format. Ideally, it should have worked .accdb format as well but there seems to be someproblem that our technical team is looking into. Thanks a lot for your help.
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top