Syntax error for creating database connection

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
393
Office Version
  1. 365
Platform
  1. Windows
archmaesters, the connection line went wrong, how do I correct it? Thanks connection1.Open: "provider= microsoft.jet.oledb.4.0; extended properties= excel.8.0; data source=" & ThisWorkbook.path & "/database/exceldata.xls"

VBA Code:
Sub adddata()
Dim connection1 As New ADODB.Connection
Dim command1 As String
connection1.Open: "provider= microsoft.jet.oledb.4.0; extended properties= excel.8.0; data source=" & ThisWorkbook.path & "/database/exceldata.xls"
sql = " insert into [sheet1$] (name, age, gender)  values('jesus', 27, 'male')"

connection1.Execute sql
connection1.Close
Set Connection = Nothing
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Remove the colon after Open
 
Upvote 0
If you're using 365 you should probably be using Microsoft.ACE.OLEDB.12.0 rather than microsoft.jet.oledb.4.0
 
Upvote 0
If you're using 365 you should probably be using Microsoft.ACE.OLEDB.12.0 rather than microsoft.jet.oledb.4.0
just tried not working and the tutorial saved this in classmodule. It works

VBA Code:
Property Get database12()
database12 = "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.path & "/Database/exceldata.xls"
End Property
 
Upvote 0
just tried not working and the tutorial saved this in classmodule. It works

VBA Code:
Property Get database12()
database12 = "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.path & "/Database/exceldata.xls"
End Property
nvm i copied pasted it and works again i think it's just a tiny syntax error somewhere
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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