ChDir function

B

Boon

Hello,

I am confused with the use of ChDir...

What does it do?

I have a vba code that imports the data from a text file. The database
resides on the server computer (e.g. \\wudj3k2993034\database\test.accdb)

I have the following codes

------

ChDir Application.CurrentProject.Path
DoCmd.TransferText acImportDelim, , "FSC", "FSC.txt", True

--------

What I hope to do is that I can use the test.accdb from my laptop. and be
able to import the text file that resides in the same folder as the
database.

thanks,
BOon
 
J

Jack Leach

You don't need ChDir for this (in fact, I'm not sure where you would use
ChDir in VBA... it's an old Dos function).

CurrentProject.Path is always the folder where the running copy resides.
When you open the project from a new location, CurrentProject.Path will
reflect that new location, no need to change anything.

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
S

Stuart McCall

Jack Leach said:
You don't need ChDir for this (in fact, I'm not sure where you would use
ChDir in VBA... it's an old Dos function).

Well if you're only accessing one or a few files it's not of much use, but
if you need to process dozens or hundreds of files, then setting the current
directory means now you only have to specify the file name (without path),
which is more efficient than concatenating the path every time.
 
D

Douglas J. Steele

In other words,

DoCmd.TransferText acImportDelim, , "FSC", Application.CurrentProject.Path &
"\FSC.txt", True

is what you should be using.
 
B

Boon

thanks all!

Douglas J. Steele said:
In other words,

DoCmd.TransferText acImportDelim, , "FSC", Application.CurrentProject.Path
& "\FSC.txt", True

is what you should be using.
 

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