Code Error

I

IT-1957

Hi,
I'm trying to move a file witha variable name to a different folder but a
get a File not Found Error, Can you help me with this?
This is the code I'm trying to use:

Function Test()

Dim SourceFile, DestinationFile, MyFile
MyFile = Dir("C:\PICTURE\*.jpg")
SourceFile = "C:\PICTURES\MyFile"
DestinationFile = "C:\Database\Test.jpg"
FileCopy SourceFile, DestinationFile

End Function

Any Help will be really appreciate it.

Thank you.
 
I

IT-1957

I tried this code which a tink is more accurate but still doesn't work.

Function Test()

Dim SourceFile, DestinationFile
SourceFile = Dir("C:\PICTURES\*.jpg")
DestinationFile = ("C:\DATABASE\TEST.jpg")

FileCopy SourceFile, DestinationFile

End Function
 
J

John Spencer

Function Test()

Dim SourceFile, DestinationFile, MyFile
MyFile = Dir("C:\PICTURE\*.jpg")
If Len(MyFile)>0 Then
SourceFile = "C:\PICTURES\" & MyFile
DestinationFile = "C:\Database\Test.jpg"
FileCopy SourceFile, DestinationFile
End If
End Function

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
J

Jack Leach

You should probably include some handling in case there's no jpg files left
in the folder (or maybe jpegs as well? they're not the same for programming
purposes).

SourceFile = Dir("C:\Test\*.jpg")
If Len(SourceFile) <> 0 Then
DestinationFile = "C:\somefile.jpg"
FileCopy, SourceFile, DestinationFile
End If

End Function

--
Jack Leach
www.tristatemachine.com

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

IT-1957

I just tried both solutions, the first one send a "File not Found" error
The second does not send any arror but nothing happens with the file. it is
not being copied.
(I'm using the Name funtion to move the file instead of copying it)
******************************************
Function FirstTest()
Dim SourceFile, DestinationFile
SourceFile = Dir("C:\PICTURES\*.jpg")
If Len(SourceFile) <> 0 Then
DestinationFile = "C:\DATABASE\TEST.jpg"
Name SourceFile As DestinationFile
End If
End Function
******************************************
Function SecondTest()
Dim SourceFile, DestinationFile, MyFile
MyFile = Dir("C:\PICTURE\*.jpg")
If Len(MyFile) > 0 Then
SourceFile = "C:\PICTURES\" & MyFile
DestinationFile = "C:\DATABASE\Test.jpg"
Name SourceFil As DestinationFile
End If
End Function
******************************************
 
I

IT-1957

Sorry I just fixed a line that had one letter missing on the SecondTest
function, on the line: Name SourceFil As DestinationFile - I added the "e"

This code works but will REMOVE the PICTURES folder (and its contents) and
create a subfolder in the DATABASE folder as Test.jpg (yes a folder) and
inside the Test.jpg subfolder will be the .jpg file.

Any Idea?
 
I

IT-1957

Nothing happens with this code:

Function SecondTest()
Dim SourceFile, DestinationFile, MyFile
MyFile = Dir("C:\PICTURE\*.jpg")
If Len(MyFile) > 0 Then
SourceFile = "C:\PICTURES\" & MyFile
DestinationFile = "C:\DATABASE\Test.jpg"
FileCopy SourceFile, DestinationFile
End If
End Function

Te explained on my previous replay is what happens with this code:

Function SecondTest()
Dim SourceFile, DestinationFile, MyFile
MyFile = Dir("C:\PICTURE\*.jpg")
'If Len(MyFile) > 0 Then
SourceFile = "C:\PICTURES\" & MyFile
DestinationFile = "C:\DATABASE\Test.jpg"
Name SourceFile As DestinationFile
'End If
End Function

I want to move the *.jpg from the PICTURES folder to the DATABASE folder.
 
J

John Spencer

Is it C:\Picture or C:\Pictures? You have two different directories being
referenced in your code.

Function SecondTest()
Dim SourceFile, DestinationFile, MyFile
MyFile = Dir("C:\PICTURE\*.jpg")
If Len(MyFile) = 0 Then
Msgbox "No file in C:\PICTURE\*.jpg"
Else 'Is it C:\Picture or C:\Pictures????
SourceFile = "C:\PICTURE\" & MyFile
DestinationFile = "C:\DATABASE\Test.jpg"
FileCopy SourceFile, DestinationFile
End If
End Function

FileCopy makes a copy in the destination directory and the original remains in
C:\Picture directory.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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

Similar Threads


Top