Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Importing / Linking / April 2005

Tip: Looking for answers? Try searching our database.

auto linking to files that change names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
br - 22 Apr 2005 03:09 GMT
I am setting up an Access application to automatically read and parse .csv
files that are generated via script on a remote server.  

The catch is that the .csv file name changes everyday according to the date.
For example, the files look like:

"QOR_DAILY_04152005.CSV"
"QOR_DAILY_04162005.CSV"
"QOR_DAILY_04172005.CSV"
...and so forth

The data format contained in the .csv file is the same everyday, and because
it is generated by automated script everyday, I felt that to fully automate
the entire process would save me a lot of pain down the road.

The 2 approaches that crossed my mind were:

1) Have the Access application copy the file to a local location, and
truncate the date, then link to the local file (i.e. file name would be:
'QOR_DAILY.CSV")

2) Set up VB Access code that would dynamically change the .csv link to look
for a file and date combo.  The control would be to have a tbllog that would
store the file and historical dates already appended.

However, I don't know if either of these are possible with MS Access 2000?  
So, are these ideas possible???? Or do I need to start looking for a
different application to complete this project?

Thanks for your suggestions.
Nikos Yannacopoulos - 22 Apr 2005 07:01 GMT
A2K is definitely capable of handling this. I have a third alternative
to offer though, which is basically to import the .csv file without
linking. You will need to do a manual import once so you create and save
an Import Sec, then you can use that in a TransferText method in VBA.
The "construction" of the .csv file name to import is very easy,
something like:

vImportFile = "QOR_DAILY_" & Format(Date, "mmddyyyy") & ".csv"

HTH,
Nikos

> I am setting up an Access application to automatically read and parse .csv
> files that are generated via script on a remote server.  
[quoted text clipped - 26 lines]
>
> Thanks for your suggestions.
Klatuu - 22 Apr 2005 22:47 GMT
Very Clever, Nikos!
The only problem I see is either loading the same day twice (May not be a
problem) or skipping a day.  If this could be a problem, then it might be
helpful to have a table of files downloaded.  Have the procedure look for the
last day loaded, add a day to it, check to see if the new date is a date that
a load would be expected (like are weekends and holidays skipped), and do
this until you have a good date, then go import the file.
May be of no value, but I am just thinking out loud. well, no THIS WOULD BE
OUT LOUD :)

> A2K is definitely capable of handling this. I have a third alternative
> to offer though, which is basically to import the .csv file without
[quoted text clipped - 38 lines]
> >
> > Thanks for your suggestions.
Nikos Yannacopoulos - 25 Apr 2005 07:40 GMT
Klatuu,

I was merely answering the particular question, but your point is valid
nonetheless. Actually I take a different approach: I have an extra field
for date in the table I import into, which I populate with the file date
(data date, not file system date) during import. I go through all files
in the particular folder, check to make sure that there are no records
in the table for a given file's date, if successful I import, I then
verify that the number of records imported equals the number of lines in
the file (minus header/footer lines), if matching I rename the file (so
it won't be imported again, but remains available just in case - clear
out those older than a week), or issue a warning message otherwise; then
move on to the next file. So, if the import process doesn't happen
everyday I don't miss anything, there are checks for successful import
etc. I suppose there can be more approaches proposed, each with its pros
and cons, this was just my $0.02's worth.

Nikos

> Very Clever, Nikos!
> The only problem I see is either loading the same day twice (May not be a
[quoted text clipped - 48 lines]
>>>
>>>Thanks for your suggestions.
Klatuu - 25 Apr 2005 13:51 GMT
Nikos,
Sorry if you thought I was being contray.  I see your posts out here
regularly and you always have good ideas.  I was not trying to contradict
what you had to say, only adding to it.
This is the interesting part of this group to me.  I get to see a lot of
different ways to get to the same place.  I learn from it daily.

> Klatuu,
>
[quoted text clipped - 67 lines]
> >>>
> >>>Thanks for your suggestions.
Nikos Yannacopoulos - 25 Apr 2005 14:30 GMT
Klatuu,

Don't worry, I didn't get the wrong idea. I just saw you build on my
reply, and thought it was worth building on it a bit further.

Regards,
Nikos

> Nikos,
> Sorry if you thought I was being contray.  I see your posts out here
[quoted text clipped - 74 lines]
>>>>>
>>>>>Thanks for your suggestions.
John Nurick - 22 Apr 2005 07:42 GMT
All this is quite possible using Access.

One thing you could do (if you just need to get at "today's" file) is to
write code that generates the file name and creates the SQL statement to
import it, e.g. this untested snippet:

 Dim strFileName as String
 Const F_FOLDER = "D:\Folder\Sub folder\"
 Const F_EXT = "CSV"
 Dim strSQL As String

 strFileName = "QOR_DAILY_" & Format(Date(), "mmddyyyy")

 strSQL = "INSERT INTO MyTable SELECT * FROM [Text;HDR=No;Database=" _
   & F_FOLDER & ";].[" & strFileName & "]#[" & F_EXT & "];"
 
 CurrentDB.Execute strSQL, dbFailOnError

Or if you just want the text file parsed and accessible to your code,
omit the INSERT INTO MyTable clause from strSQL and open a recordset

 Dim rsR = DAO.Recordset
 ...
 Set rsR = CurrentDB.OpenRecordset(strSQL, dbOpenSnapshot)
 ...

 

 

>I am setting up an Access application to automatically read and parse .csv
>files that are generated via script on a remote server.  
[quoted text clipped - 26 lines]
>
>Thanks for your suggestions.

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.