|
-
Sep 13th, 2000, 08:34 AM
#1
Thread Starter
Addicted Member
I've been at this for ages and can't seem to get it to work.
Code:
Private Function MakeFolder(NewDir As String)
Dim dirname As String
dirname = "C:\TestOrator\"
NewDir = dirname & NewDir
MkDir NewDir
End Function
Private Sub Archive_Click()
today = Format(Now, "dd mmmm yyyy")
MakeFolder (today)
Call CopyA
End Sub
Public Sub CopyA()
Dim FSO As Object
On Error GoTo NOFSO
Set FSO = CreateObject("Scripting.FileSystemObject")
today = Format(Now, "dd mmmm yyyy")
On Error Resume Next
FSO.CopyFile "C:\TestOrator\Outgone\*.gen", Makefolder(today), True
FSO.DeleteFile "C:\TestOrator\Outgone\*.gen"
Set FSO = Nothing
Exit Sub
NOFSO:
MsgBox "FSO CreateObject Failed, Copying of files"
End Sub
The error I get is a byref argument type mismatch. I'm not sure if it is possible to use FileCopy in this manner. The destination Folder is being generated daily for archiving purposes so the name is different every day. Can someone please help, I'm really stuck with this problem. Thanks
-
Sep 13th, 2000, 08:59 AM
#2
_______
'you should also use Option Expicit function
'you should implement a check to see if the dir exist
'before your create it..possibility of error if it
'does exist.
Code:
Option Explicit
Private Function MakeFolder(NewDir As String)
Dim dirname As String
dirname = "C:\TestOrator\"
'changed it here get to the root dir and then add subdir
ChDir dirname
If Dir(newdir, vbDirectory) <> "" Then
MsgBox "Exist Already"
Else
MkDir NewDir
endif
End Function
Private Sub Archive_Click()
today = Format(Now, "dd mmmm yyyy")
MakeFolder (today)
Call CopyA
End Sub
Public Sub CopyA()
'add this: you referenced a string in function and
'then you passed a date
Dim today As String
Dim FSO As Object
On Error GoTo NOFSO
Set FSO = CreateObject("Scripting.FileSystemObject")
today = Format(Now, "dd mmmm yyyy")
On Error Resume Next
FSO.CopyFile "C:\TestOrator\Outgone\*.gen", MakeFolder(today), True
FSO.DeleteFile "C:\TestOrator\Outgone\*.gen"
Set FSO = Nothing
Exit Sub
NOFSO:
MsgBox "FSO CreateObject Failed, Copying of files"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 13th, 2000, 09:13 AM
#3
Thread Starter
Addicted Member
Thanks for the help. I just tried that and I get a Compile error that Variable is not defined and it points to this part of code
Code:
Private Sub Archive_Click()
today = Format(Now, "dd mmmm yyyy")
MakeFolder (today)
Call CopyA
End Sub
Have I left something out?? Thanks again your help is really valued
-
Sep 13th, 2000, 09:20 AM
#4
Addicted Member
Hi,
you haven't declared today in the sub:
Code:
Private Sub Archive_Click()
Dim today as String 'missed out
today = Format(Now, "dd mmmm yyyy")
MakeFolder (today)
Call CopyA
End Sub
Hope this helps
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Sep 13th, 2000, 09:24 AM
#5
_______
<?>
As S@NSIS pointed out..failure to declare.
That is what Option Explict does.
It forces you to declare your variables.
Very good practice if you are working with a lot
of variables..no dupes permitted and you must declare
all so your code will be cleaner.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 13th, 2000, 09:35 AM
#6
Thread Starter
Addicted Member
Thanks a lot once again. I've gotten rid of the error messages now, but the FileCopy isn't copying any files over at all. Is there something wrong with the way that I am way I using FileCopy.
Thanks guys
-
Sep 13th, 2000, 09:51 AM
#7
_______
<?>
Code:
'added a public var for your dirname
Public MyNewDir As String
Option Explicit
Private Function MakeFolder(NewDir As String)
Dim dirname As String
dirname = "C:\TestOrator\"
ChDir dirname
If Dir(NewDir, vbDirectory) <> "" Then
MsgBox "Exist Already"
Else
MkDir NewDir
MyNewDir = NewDir
End If
End Function
Private Sub Archive_Click()
Dim today As String
today = Format(Now, "dd mmmm yyyy")
MakeFolder (today)
Call CopyA
End Sub
Public Sub CopyA()
'add this: you referenced a string in function and
'then you passed a date
Dim today As String
Dim FSO As Object
On Error GoTo NOFSO
Set FSO = CreateObject("Scripting.FileSystemObject")
today = Format(Now, "dd mmmm yyyy")
On Error Resume Next
'copy it to MyNewDir as the dir is already created
FSO.CopyFile "C:\TestOrator\Outgone\*.txt", MyNewDir, True
FSO.DeleteFile "C:\TestOrator\Outgone\*.txt"
Set FSO = Nothing
Exit Sub
NOFSO:
MsgBox "FSO CreateObject Failed, Copying of files"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 13th, 2000, 10:03 AM
#8
Thread Starter
Addicted Member
Thanks a lot HeSaidJoe, your a champion. I got it to transfer the files. The only part I couldn't get to work was that check at the top:
Code:
Private Function MakeFolder(NewDir As String)
Dim dirname As String
dirname = "C:\TestOrator\"
ChDir dirname
If Dir(NewDir, vbDirectory) <> "" Then
MsgBox "Exist Already"
Else
MkDir NewDir
MyNewDir = NewDir
End If
End Function
It transfers the files when I leave this part as:
Code:
Private Function MakeFolder(NewDir As String)
Dim dirname As String
dirname = "C:\TestOrator\"
NewDir = dirname & NewDir
MkDir NewDir
MyNewDir = NewDir
End Function
Thanks a million for your help, I reall appreciate it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|