Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 15th, 2006, 06:34 PM
DBN DBN is offline
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Importing a text file

I am using TransferText to import a CSV file into a database. It requires that the user type in the name of the file. Does anyone know how to make this or some other command look for a file regardless of its name in a folder somewhere so that the user would simply need to put the files they want imported into that folder and the app would do the rest?

Thanks.
 
Old April 20th, 2006, 01:16 AM
Authorized User
 
Join Date: Mar 2006
Location: Bratislava, , Slovakia.
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
use ActiveX component CommonDialog, or it's API implementation
Peko

 
Old April 20th, 2006, 07:53 AM
DBN DBN is offline
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Peko! I'll give it a try.

DBN

 
Old April 21st, 2006, 02:58 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I'm not sure I follow the process. It sounds like you have a desire to “poll” a folder, but you liked peko’s suggestion, which is an animal of a different stripe...

Could you write a short story describing the actions of the user, and the required actions of the computer? That would be helpful.
 
Old April 21st, 2006, 05:16 PM
DBN DBN is offline
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a process which imports a .csv file into Access and incorporates the data into various tables. The users get this data from another process, and that process creates a file with a time/date stamp such as 20060405123456. It is always in 1 folder. Currently, I require the user to type in the time/date stamp part because the first part is always the same. I take this part and append it to the standard file name so that I know exactly what the file is called, looking for it with its full path name with a docmd.transfertext command.

Of course, the user would rather not have to type in that cryptic set of numbers. I would like to be able to have my VBA code "poll" the folder for files, and iteratively import them, if there is more than 1. Is this possible, and how would I do that?

Thanks.

 
Old April 24th, 2006, 02:31 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Polling is pretty easy; You just set up some timer routine (a stopwatch on a form is a great way to do this).
At each time period, you read the filenames out of the predefined folder.
Having processed a file, you can move it to a different location (which is the best process, I feel)—being sure to set up your code to gracefully handle problems like trying to copy the file if a file of that name already exists—or delete it (second best), or keep track of what you have already processed, and ignore files still in the folder but already processed.
You can look for files with Dir() and a loop (see code at the bottom of this post), or you can use the FileSystemObject (which I love).

Having found a possible processing candidate, you can get the file’s date/time stamp, or you can rely on the file’s name.
You can add controls allowing the user to have a calendar/clock type interface that is more human-friendly, and convert their input to the computer-friendly string that you indicate the files carry as their name.

To use the FileSystemObject, add a reference in your project to the Microsoft Scripting Runtime (C:\WinNT\System32\scrrun.dll, on my machine). Help can provide you additional details on this really helpful class.

Does that help?
Code:
    Dim s As String

    s = Dir$("C:\TheFileLoc\*.csv")    ' returns just the filename.ext
    Do Until s = ""
        Process("C:\TheFileLoc\" & s)  ' Process would be a user-defined routine
        s = Dir$()                     ' REturns name of next file fitting initial speci-
    Loop                               ' fication, or "" is no more.
 
Old April 24th, 2006, 02:52 PM
DBN DBN is offline
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear BrianWren,

This sounds like just what I need. I am going to give it a try and will let you know how it turns out.

Thanks so much for responding. This new process will really improve my app.

DBN





Similar Threads
Thread Thread Starter Forum Replies Last Post
importing text file into excel stealthdevil Excel VBA 2 July 10th, 2007 11:28 AM
Importing text file into excel anamarijaf Excel VBA 4 January 27th, 2007 05:50 AM
Importing data from a text file nav PHP How-To 2 March 7th, 2005 02:42 PM
Importing a text file to excel using VB ridders Excel VBA 1 April 10th, 2004 03:01 PM
Problem importing text file manuel Access 3 April 7th, 2004 09:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.