Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting an Excel Spreadsheet to an Access Table

Status
Not open for further replies.

LongFeiFengWu

Technical User
Nov 9, 2001
98
US
This is something new to me that I've been challenged with by my superiors. I've been able to set up an ODBC connection to an Excel spreadsheet on my server, but don't know how to call the data from the spreadsheet since there are no column headings. Do I just reference A,B,C,D like I would reference columns ID,Name,EntryDate in Access?

Any Help Will Be Appreciated.

"If nothing within you stays rigid, outward things will disclose themselves. Moving, be like water. Still, be like a mirror. Respond like an echo." ~ Bruce Lee
 
You shoud be able to do a SELECT * rom the worksheet and then just referencethefields by index instead of by name, something like:
Code:
Dim excRS, excConn

Set excConn = Server.CreateObject("ADODB.Connection")
excConn.Open "your connection string to excel file"

Set excRS = excConn.Execute("SELECT * FROM [Sheet1$]")

If Not excRS.EOF Then
   excRS.MoveFirst

   'sample loop and output
   Response.Write "<table>"
   Do Until excRS.EOF
      Response.Write "<tr>"

      'first field
      Response.Write "<td>" & excRS(0) & "</td>"
      'second field
      Response.Write "<td>" & excRS(1) & "</td>"
      'third field
      Response.Write "<td>" & excRS(2) & "</td>"

      Response.Write "</tr>"
      excRS.MoveNext
   Loop
   Response.Write "</table>"
End If

Set excRS = Nothing
excConn.Close
Set excConn = Nothing

So basically you can select * from the sheet, which allowsyou to ignore the column name issue in your select statement. Then you can reference the columns based on their index in the recordset rather then their names, again not needing a name.


According to MS the connection is supposed to specify a name for you if you set the HDR attribute = NO in your connection string, something like Fn, ie F1, F2, F3, etc. But these don't seem to be much more helpful then just using the numeric index above. Here is the link to the page I found that on: Even though it is a VBA/VB example the ADO object should work the same regardless of wat language your using it from.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top