Hi all, i encounter an syntax error "Syntax Error in Insert Into" when i try to run this code... anyone can assist? Thanks!

Dim sConnectionString As String
sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=H:\Users\Desktop\EmployeeAway2.xlsx;Extended Properties=""Excel 12.0;HDR=YES;"""
Dim objConn As New System.Data.OleDb.OleDbConnection(sConnectionString)
Dim objCmd As New System.Data.OleDb.OleDbCommand()
objCmd.Connection = objConn
objCmd.CommandText = "Insert into [Sheet1$] (EmployeeID, DateFiled, Name, Department, Reason, From, To, NumberofDays, LeaveApplied, ApprovedBy)" & _
" Values ('John', 'John', 'John', 'John', 'John', 'John', 'John', 'John', 'John', 'Thomas')"

Recommended Answers

All 2 Replies

I think it may be because FROM and TO are reserved words. You need to delimit them as you have Sheet1$. Or rename your columns because that'll catch you out time and again...

yup! i solved the error! Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.