VB5 FileCopy

Thanks in advance for helping me out.

I am having trouble using "FileCopy."  The specific file being copied is the file that listed in the textbox and it will always go to the same directory.  I assigned variable Destination to "c:test" and SourceFile to "file1.filename."  I am getting error number 56.

Dim SourceFile As String
Dim Destination As String

Private Sub File1_Click()
    txbFileName.Text = File1.filename
    SourceFile = File1.filename
   
End Sub

Private Sub cmdSend_Click()
    FName = txbFileName.Text
    FileCopy SourceFile, Destination
End Sub
LClosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kamallCommented:
LClos,
Your destination file name syntax is incorrect.
Use "c:\test" instead of "c:test".
Regards
0
LClosAuthor Commented:
Thanks for the response, but the "\" left out was only a typo in my submitted question.  I still get the error.  The error number is 53 not 56.  I can submit more code if needed.
0
kamallCommented:
Well LClos,
The error number 53 is "file not found".
Yes, the problem is that you are giving the source file as File1.FileName but you are not supplying the full pathname. You must write:
SourceFile = File1.Path & "\" & File1.FileName

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

kamallCommented:
kamall:
Almost, you missed the "\"

The code should be:
  SourceFile = File1.Path
  If Right$(SourceFile, 1) <> "\" Then
    SourceFile = SourceFile & "\"
  End If
  SourceFile = SourceFile & File1.Filename

0
clifABBCommented:
kamall:
My apologies, you caught it.  :)
0
clifABBCommented:
Now, I have error 75 (access to path).  I plan on giving you the points since your answer helped me greatly.  And, I will increase them if you stick with me 'til I get this file to copy. You are more than welcome to let me know what kind of points you think this is worth.  Thanks.
0
LClosAuthor Commented:
ha ha ha ha ha..... clifABB,
You made me laugh, man.
I was faster :-)
Anyway, thanks for your contribution.

Well LClos, thank you for your kind offer regarding the points. I will leave this to you to decide.
Also, I will "stick" with you until we bring it to an end.

Now....
Look for the following regrding error #75 (from the VB help):

---------------------------------------------------------------
During a file- or disk-access operation (for example, Open, MkDir, ChDir, or RmDir), the operating system could not make a connection between the path and the filename.  This error has the following causes and solutions:  

The file specification is not correctly formatted.

A filename can contain a fully qualified (absolute) or relative path.  A fully qualified path starts with the drive name (if the path is on another drive) and lists the explicit path from the root to the file.  Any path that is not fully qualified is relative to the current drive and directory.

You attempted to save a file that would replace an existing read-only file.

Change the read-only attribute of the target file or save the file with a different filename.

You attempted to open a read-only file in sequential Output or Append mode.

Open the file in Input mode or change the read-only attribute of the file.
---------------------------------------------------------------

I think I can help you more if you post your code.
0
kamallCommented:
I also suggest the following:
Before your FileCopy statement, write the following code to check the file names:

MsgBox SourceFile & chr(10) & Destination

This will show you the full path/filename of both source and destination files.

Also, I would like to know, where you define your destination file name? Is it a global variable and you assign it in your form load event for example?

Anyway, the code above will show you the real things.
I suggest you test with the code above and check the things before posting your code.
0
kamallCommented:
Here is my code in its entirety:

Dim SourceFile As String
Dim Destination As String

Private Sub cboFileType_Click()
 Select Case cboFileType.ListIndex
    Case 0
        File1.Pattern = "*.est"
    Case 1
        File1.Pattern = "*.mod"
    Case 2
        File1.Pattern = "*.pat"
    End Select
End Sub

Private Sub cmdSend_Click()
    FName = txbFileName.Text
    MsgBox SourceFile & Chr(10) & Destination
    FileCopy SourceFile, Destination
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    Label2.Caption = Dir1.Path
   
    If File1.filename <> "" Then
        txbFileName.Text = File1.filename
    Else
        txbFileName.Text = File1.Pattern
    End If
   
End Sub

Private Sub Drive1_Change()
    Dim Msg As String
   
    On Error Resume Next
   
    Screen.MousePointer = 11 ' Hour glass pointer
    Dir1.Path = Drive1.Drive
    Screen.MousePointer = 0
   
    If Err Then 'Dir1 tried to become a bad or unavailable drive
        Msg = "Error " & Err & ": " & Error$ & "."
        MsgBox Msg, 48, "Drive/Directory Error"
        Drive1.Drive = Dir1.Path
    End If
   
    On Error GoTo 0
End Sub

Private Sub File1_Click()
    txbFileName.Text = File1.filename
   SourceFile = File1.Path & "\" & File1.filename
   
End Sub

Private Sub Form_Load()
    cboFileType.AddItem "Establishment (*.est)"
    cboFileType.AddItem "Modification (*.mod)"
    cboFileType.AddItem "Paternity (*.pat)"
   
    File1.Path = "d:\temp\test"
    Dir1.Path = File1.Path
    Destination = "d:\temp"

    If File1.filename <> "" Then
        txbFileName.Text = File1.filename
    Else
        txbFileName.Text = File1.Pattern
    End If
End Sub

0
LClosAuthor Commented:
LClos,
Here is your mistake:
Destination = "d:\temp"
Destination is an existing directory in your D drive. You can not assign a destination file name the name of an existing directory.
For your code to work, you should change the following code:

Private Sub cmdSend_Click()
           FName = txbFileName.Text
           MsgBox SourceFile & Chr(10) & Destination
           FileCopy SourceFile, Destination
End Sub

TO:

Private Sub cmdSend_Click()
           FName = txbFileName.Text
           Destination = Destination & "\Myfile.xxx"
           MsgBox SourceFile & Chr(10) & Destination
           FileCopy SourceFile, Destination
End Sub

where "\Myfile.xxx" is the full path/name of your destination file that will be created (copied into).
0
kamallCommented:
Wah Hoo!  Finally something copied!  But, I still have the problem of the name of the file.  How do I make sure the file name stays the same?

When I tried:  Destination = Destination & "\FName" it named the file FName.

thanks so much.  I am new to this, but you've probably guessed that by now.  


0
LClosAuthor Commented:
Its as easy as that:
Modify the
   Destination = Destination & "\Myfile.xxx"
To
   Destination = Destination & "\" & File1.FileName
0
kamallCommented:
Excellent.  I am very appreciative of the help this person gave me.  They were very patient throughout the process.  I am very new to this and sometimes, the smallest of things will trip me up.  This person made it possible for me to go home on time for a change and not think about this problem in the middle of the night.
0
LClosAuthor Commented:
I am very glad for solving your problem and for your feeling LClos.
Have a nice day.
Best regards
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.