Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move FILE programicaly from ACCESS 1

Status
Not open for further replies.

heehaw

Programmer
Mar 2, 2002
11
0
0
US
Looking a line of code that would enable a user from inside of Access to move a file to the Floppy Drive that is contained outside of Access on the C:

Example: User needs to move a flie to the floppy drive and by clicking a button, a file is copied to the A: The file would be on the C: and lets say it's in a folder called "Move". User clicks a button and a small file contained in C:\Move is copied to the A: drive.

Can't seem to get it to work. Any ideas?

Heehaw
 
HeeHaw,

(a) Use the filecopy command in the OnClick event code behind a button; for example:

FileCopy "C:\SomeFolder\File.Dat", "A:\File.Dat"

(b) If you need to remove the original file, use the Kill command; eg.

Kill "C:\SomeFolder\File.Dat"

(c) If you need to determine the names of files within a nominated folder, use the "DIR" function. Look up the details in the Access on-line help.

Combination of these three points should help you to solve your requirement,

Hope this helps,
Steve
 
That did it. I wasn't listing the destination DB correctly and you helped that.

Many Thanks

Terry (heehaw)
 
Yes, does'nt work like the old DOS used to; you need to supply ALL of the destination drive, path, filename, extention components.
Cheers,
Steve
 
heehaw - suppose ya like country music, eh?

Interesting problem, the following code:

Private Sub Command6_Click()
Dim SourceFile, DestinationFile
SourceFile = "C:\MyFile.txt" ' Define source file name.
DestinationFile = "A:\MyFile.txt" ' Define target file name.
FileCopy SourceFile, DestinationFile ' Copy source to target.
Exit Sub
End Sub

...seems to be looking for some type of external library since it "can't find the file"...we'll have to wait for someone to drop by and clarify this...
 
I posted my answer from an email so didn't see Steve's response. I tried this particular line of code:

FileCopy "C:\MyFile.txt", "C:\NewFolder\MyFile.txt"

..and kept getting an Error message "Can't find File"...so, it may work for you guys, but it ain't working on my machine (Windows XP, Access 2000)...any ideas?
 
Isadore,
Only the obvious question. Are you SURE that your source file (C:\MyFile.txt) physically exists. If it doesnt you get a "Run time error '53' - File not Found". I presume this is the wording of your error?

Also make sure that the destination folder exists before you run the code. It won't automatically be created. You'll get another error if the folder doesnt exist.
Cheers,
Steve
 
Steve -

Yes, the Error was '53' File Not Found, and yes, the field MyFile.txt is on the C: root, and I try to send it to C:\AWW which is an existing folder on the C: drive. This is what frustrated me when I was answering this post because the vba line should have been a "one liner" and I spent 1 hr trying this and that, etc... So something is up, that is why I was wondering if a dll library was missing or something of that order...even now, it does not work? Strange indeed...
 
Isadore,
Yes, sure sounds like a strange one. Let me offer the following:

(a) Can you try running the program without change on another computer.

(b) Can you try running the program the program using a different source data file, (eg. C:\autoexec.bat); perhaps there's some particular attribute setting on the file you're selecting which is making it non visible to the FileCopy command.

(c) Final resort; uninstall and re-install Access.

Good Luck,
Steve
 
THis solution calls a DOS batch file. I have included both the access code and the DOS batch file text:

Access Code:
'-----------
VersionNoFile = "h:\apps\ft98\v2-4-14.txt"
If Len(Dir$(VersionNoFile)) = 0 Then 'file not found
'DoCmd.OpenForm "TextFileLocation", , , , , acDialog
MsgBox "A new version is available." & Chr(13) & Chr(13) & "1. Double-click the 'Perform Upgrade' icon." & Chr(13) & Chr(13) & "2. Logon to FasTrade 98 again." & Chr(13) & Chr(13) & "FasTrade 98 will now close.", 16, "FasTrade 98"
Application.Quit
End If

DOS batch file referred to as Perform Upgrade icon above:
'--------------------------------------------------------
echo off
cls
echo *** Upgrading Version... ***
echo.
echo 2 files to copy.
echo.
echo Copying file 1...
del c:\Progra~1\FasTra~1\FTApplNT.* 'del source files
copy h:\apps\ft98\FTApplNT.bmp d:\Progra~1\FasTra~1\FTApplNT.bmp
echo.
echo Copying file 2...
copy h:\apps\ft98\FTApplNT.mde d:\Progra~1\FasTra~1\FTApplNT.mde
if not errorlevel 1 goto end
cls
beep
echo ERROR: Could not upgrade to the new version. Contact your software support specialist.
:end
echo.
echo *** Upgrade complete! ***
echo.
rem pause

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top