transfer spreadsheet

ajetrumpet

Banned
Local time
Today, 04:59
Joined
Jun 22, 2007
Messages
5,628
Folks,

I need to use the transfer spreadsheet function to get an unknown amount of rows from Excel over into an existing table in Access. I am getting this data off of the internet, into a CSV, and then over to Access that way.

I need to use code similar to the .xlDown syntax in Excel (in place of the range I have specified). Can I write that with the function? Does Access read it?

Here are the steps I got right now. If it's not the best, please suggest how I can improve the process. thanks!
Code:
Dim strTABLE As String

strTABLE = "my" & MonthName(Month(Date)) & "transactions"

  DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "mymarchtransactions", _
                            "mymarchtransactions.csv", no, [u][color=red][B]"A2:D100"[/B][/u][/color]

DoCmd.SetWarnings False

    DoCmd.RunSQL "INSERT INTO tblzone (transactiondate, Postingdate, transactiondescription, amount) " & _
                 "SELECT [f1], [f2], [f3], [f4] FROM " & strTABLE

DoCmd.SetWarnings True

      CurrentDb.TableDefs.Delete (strTABLE)
 
Use the address property of the range object to return the range you want to import.
 
I don't think I followed that Chergh....

Should I experiment with this in Excel or can you give me a syntax hint here...???
 
Create a spreadsheet with some data in the first row and then run the following code in the immediate window.

Code:
debug.Print thisworkbook.Worksheets("Sheet1").range("A1").end(xltoright).address(RowAbsolute:=False, columnabsolute:=false)
 
You dont need to specify a range... if you dont, access will simply import all :)
 
Thank you chergh.

Namliam,

sometimes I can't import all, because the first row will contain column headings (sometimes), and I don't want those...
 
Namliam,

sometimes I can't import all, because the first row will contain column headings (sometimes), and I don't want those...

When an excel sheet contains headers I allways import into a staging table to "circumvent" the headers while storing the data into a table.
Then append to my final table, this prevents a lot of mess.
 

Users who are viewing this thread

Back
Top Bottom