I tried that already...but it doens't run.
I believe HDR=YES is default.
Main Topics
Browse All TopicsHi all,
I'm trying to get data from an excel file (2000/2003).
To connect to the excelfile and do a simple query is rather easy:
Set Con = CreateObject("ADODB.Connec
StrCon = "Provider=Microsoft.Jet.OL
"Data Source=c:\test.xls;" & _
"Extended Properties=Excel 8.0;"
Con.Connectionstring= StrCon
Con.open
Set rst = con.execute("SELECT * FROM [sheet1$A4:BE60]")
The excelsheet has several columns: nr, 1,2,3,4,5,6,7,8,9,10
Now I want to select the column "nr" and add up column "1","2","3" and "4" so I try this:
Set rst = con.execute("SELECT nr,[1]+[2]+[3]+[4] AS total FROM [sheet1$A4:BE60]")
This does not work and I get an error message(the error message is in dutch so I don't think it would be usefull to post it here). I'm not sure what I am doing wrong, because I tried a simular query in MsAccess 2000 and it does work there. Anyone who can help me out here?
Thanks in advance!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try changing the last line of your connection string to:
"Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;"""
IMEX=1 will help ADO to not use datatypes that are inconsistent with the values in your spreadsheet and HDR=1 tells ADO that your column names are in the first row of the range that you specified... (I am assuming that this is true.) If your column names are not in [sheet1$A4:BE4] then you should make sure that they are or that you correct the range to include the column names.
Are you Dutch? Or, rather, can you read Dutch? If so then maybe you could give us a rough translation or the error message that you are recieving... At least see if you can give us the error number.
Hi,
I tried adjusting the connectionstring but with the same result.
The column names are included in the range [sheet1$A4:BE4]
I know dutch.
This is a rough translation of the error message:
Runtime Error '-2147217904 (80040e10)':
Values for one or more required parameters missing
this works:
Set RST = Con.Execute("SELECT nr+nr as totaal FROM [projecten$A4:BE60] WHERE NR <> ''")
this doesn't:
Set RST = Con.Execute("SELECT [1]+[2] as totaal FROM [projecten$A4:BE60] WHERE NR <> ''")
I think something is wring with the "[" and "]" and the numbers that are used as columnnames. Oh..by the way...I can't change the column names in the excel sheet.
any ideas?
1. Do you really have 57 columns??? If so then do you need to include them all in your query or can you include only the columns that you need? (i.e. projecten$A5:E60)
2. Is all of the data in the table numeric? (You can modify the code below to print out the datatype of the columns if you are unsure.)
3. Try using your code above (including the column header range) to SELECT * from your table and then loop through the columns and print the field names out and make sure that you have the names correct:
for i =0 to rst.fields.count - 1
debug.pring rst.fields(0).name
next i
Thanks.... this is very helpfull.
I just checked...with HDR=YES, the columns with numbers as name are still named F5, F6, Fx.
Columns that have text as name have that text as their column name.
How d#mb of me not the look at the fieldnames in the first place.
Anyway...here are your points! Thanks again.
I tried running this, but it failed. I think it's best to assume ignore the Excel part when looking at a csv or txt file, but am not sure how to code the connection string. The worksheet name is test
Set con = CreateObject("ADODB.Connec
StrCon = "Provider=Microsoft.Jet.OL
"Data Source=c:\test.csv;" & _
"Extended Properties=Excel 8.0;IMEX=1;HDR=YES;"
con.Connectionstring = StrCon
con.open
Set rst = con.execute("SELECT * FROM test")
Business Accounts
Answer for Membership
by: leonstrykerPosted on 2004-12-28 at 07:10:39ID: 12912600
Does this run?
EDB.4.0;" & _
"SELECT nr, [1] FROM [sheet1$A4:BE60]")
You should try adding a header parameter to your connection string
StrCon = "Provider=Microsoft.Jet.OL
"Data Source=c:\test.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes"""
Leon