Solved

VB5 FileCopy

Posted on 1998-05-07
14
697 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:LClos
  • 7
  • 5
  • 2
14 Comments
 
LVL 7

Expert Comment

by:kamall
Comment Utility
LClos,
Your destination file name syntax is incorrect.
Use "c:\test" instead of "c:test".
Regards
0
 

Author Comment

by:LClos
Comment Utility
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
 
LVL 7

Accepted Solution

by:
kamall earned 100 total points
Comment Utility
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
 
LVL 7

Expert Comment

by:kamall
Comment Utility
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
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
kamall:
My apologies, you caught it.  :)
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
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
 

Author Comment

by:LClos
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 7

Expert Comment

by:kamall
Comment Utility
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
 
LVL 7

Expert Comment

by:kamall
Comment Utility
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
 

Author Comment

by:LClos
Comment Utility
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
 
LVL 7

Expert Comment

by:kamall
Comment Utility
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
 

Author Comment

by:LClos
Comment Utility
Its as easy as that:
Modify the
   Destination = Destination & "\Myfile.xxx"
To
   Destination = Destination & "\" & File1.FileName
0
 
LVL 7

Expert Comment

by:kamall
Comment Utility
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
 

Author Comment

by:LClos
Comment Utility
I am very glad for solving your problem and for your feeling LClos.
Have a nice day.
Best regards
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now