transfertext

D

dogfish

I need to import a txt file everyday. I am trying to use the transferetext
from a form button onclick in Access. This option requires a named file and
full path which is a problem because the file name changes everyday, is there
a way that I can have the file name as a variable entered via a message box
or is that just being greedy? How about entering the path and it opening a
window for me to choose the file? Way too greedy
 
B

Brian

dogfish said:
I need to import a txt file everyday. I am trying to use the transferetext
from a form button onclick in Access. This option requires a named file and
full path which is a problem because the file name changes everyday, is there
a way that I can have the file name as a variable entered via a message box
or is that just being greedy? How about entering the path and it opening a
window for me to choose the file? Way too greedy

No, not too greedy at all. There is a Common Dialog control available for
use in Access, but like all ActiveX controls it is smelly and loathsome. I
use and recommend this:

http://www.mvps.org/access/api/api0001.htm
 
D

dogfish

bit too complicated for a spanner like me, all i want to do is import a
different text file from the same location every day. click a button, window
opens at c:\myimports and i pick the file and press okay.
 
B

Brian

dogfish said:
bit too complicated for a spanner like me, all i want to do is import a
different text file from the same location every day. click a button, window
opens at c:\myimports and i pick the file and press okay.

Ah, you never said you didn't want to do any work! Some might folks
consider that a touch greedy (although personally I couldn't possibly
comment).

Anyway, it isn't complicated at all. You don't need to understand all that
code: the ability to copy and paste it will suffice! So, once you've done
that, by copying and pasting the code into a new module in your database,
then something like this will get you a file name:

Dim strInitialDir As String
Dim strInputFileName As String

strInitialDir = "C:\SomeFolderOrOther"
strInputFileName = ahtCommonFileOpenSave(OpenFile:=True,
InitialDir:=strInitialDir)

And then use strInputFileName as the FileName argument of the TransferText
method.

If the users clicks the cancel button in the file dialog box,
strInputFileName will be a zero-length string i.e. "". There are lots of
options for controlling how the file dialog box appears and behaves but,
hey, why should I do all the work around here? It's all documented in the
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top