A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Appending Excel data into an Access table while inserting the file name



 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old December 17th, 2009, 06:36 PM posted to microsoft.public.access.tablesdbdesign
Greg Mathes
external usenet poster
 
Posts: 1
Default Appending Excel data into an Access table while inserting the file name

I have a loop in an Access 2003 database that appends records from multiple Excel files within a given directory. The name of each Excel file cycles through one variable (ImpFileName) as its records are imported, but I also need to add the Excel file name to each record. I wanted to assign the value of ImpFileName to the DefaultValue property of the FileName field in the table as part of the DoWhile loop, but something is wrong with my syntax.

My code is below, but only works if I comment out the line that assigns the DefaultValue property. Any help would be much appreciated!

Dim tdfImportedFiles As TableDef
Dim ImpFileName As String

Set tdfImportedFiles = CurrentDb.TableDefs!ImportedFiles

ImpPath = "C:\Temp\Course Evaluations\Working\Source\"
ImpFileName = Dir("C:\Temp\Course Evaluations\Working\Source\*.xls")
' sets a dynamic variable that scrolls through the list of Excel source files

Do While Len(ImpFileName) 0
' cycle through the list until the list is empty

'tdfImportedFiles.Fields!FileName.DefaultValue = "ImpFileName"
'set the DefaultValue property for the FileName field within the ImportedFiles table to the current ImpFileName

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "ImportedFiles", "C:\Temp\Course Evaluations\Working\Source\" & ImpFileName, True
'imports all populated rows from the spreadsheet into the ImportedFiles Table

Kill "C:\Temp\Course Evaluations\Working\Source\" & ImpFileName
'deletes the source spreadsheet once it's been imported

ImpFileName = Dir
'advances to the next file in the list

Loop


Submitted via EggHeadCafe - Software Developer Portal of Choice
Quick and easy SHA1 Hash of a String
http://www.eggheadcafe.com/tutorials...sha1-hash.aspx
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.