Syntax error for creating database connection

yxz152830

Board Regular
Joined
Oct 6, 2021
Messages
199
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

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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,066
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Remove the colon after Open
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,066
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
If you're using 365 you should probably be using Microsoft.ACE.OLEDB.12.0 rather than microsoft.jet.oledb.4.0
 

yxz152830

Board Regular
Joined
Oct 6, 2021
Messages
199
Office Version
  1. 365
Platform
  1. Windows
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
 

yxz152830

Board Regular
Joined
Oct 6, 2021
Messages
199
Office Version
  1. 365
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,774
Messages
5,766,403
Members
425,350
Latest member
procha

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
Top