AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 2,052
- Office Version
- 2019
- 2010
- Platform
- Windows
I have the following which works conditionally
The problem is strSQL. The above works as I know the Excel Column names. I can also use "*"
I remember a situation where you could have e.g. "SELECT [F1], [F2], [F3], Category, Type FROM [Sheet1$] "
but this gives error No value given for one or more required parameters.
I'm trying to figure out why.
Thanks for any advice.
VBA Code:
Sub ConnectToExcel()
'Ref needed to Microsoft ActiveX Data Objects 6.1 Library
Dim strSQL As String, conStr As String
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim ExcelFile As String
ExcelFile = "J:\Private\AcessImports\test1.xlsx"
conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & ExcelFile & "';" & _
"Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;"";"
strSQL = "SELECT Prefix, Category, Type FROM [Sheet1$] " 'WHERE [Thing1] > 1"
cnn.Open conStr
rs.Open strSQL, cnn, adOpenStatic, adLockOptimistic, adCmdText
End Sub
The problem is strSQL. The above works as I know the Excel Column names. I can also use "*"
I remember a situation where you could have e.g. "SELECT [F1], [F2], [F3], Category, Type FROM [Sheet1$] "
but this gives error No value given for one or more required parameters.
I'm trying to figure out why.
Thanks for any advice.