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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Excel 97 Files From Changing Locations

Access Howto:

Importing Excel 97 Files From Changing Locations

by  famousb  Posted    (Edited  )
Importing of Excel 97 files when you want the user to be prompted for file name and location to allow for changing directories and file names - but always to the same Access table (this is with the first example from the FAQ - Importing Excel 97 Files Into Access Using VB Code).

The following names would need to be added or changed depending upon your database, but the punctuation would remain:

AccessTableName = The name of the table in your database to which you wish to add the records.
TitleOfMessageBox = The title you wish to have on your message box.
YouCanAddDefaultLocationHere = If you want to give the user a default location from which to import.

Importing of Excel 97 files when you want the user to be prompted for file name and location to allow for changing directories and file names, but always to the same Access table. This is to import the entire first worksheet if it does not have Field Names included, to include field names change the last "0" to "-1"

You would use a series of statements as such:
Dim Message, Default, PathValue, Message2, FileValue As String
Dim Title
Message = "Enter the path name."
Message2 = "Enter the file name."
Title = "TitleOfMessageBox"
Default = "YouCanAddADefaultLocationHere"
FileValue = InputBox(Message2, Title, Default)
PathValue = InputBox(Message, Title, Default) & FileValue
DoCmd.TransferSpreadsheet acImport, 8, "AccessTableName", PathValue, 0
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top