Syntax error for creating database connection

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
387
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,213,564
Messages
6,114,334
Members
448,567
Latest member
Kuldeep90

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