Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

DSTR3 (TechnicalUser)
26 Nov 06 10:07
Hi,
I'm new to VB...I'm using VB6.  I need a command button to copy a file and place it into another directory...

Copy C:\ProServ\DB\PS.mdb to C:\ProServ\BackUp

It has to rename the file from PS.mdb to BU.Mdb and overwrite the previous BU.mdb file.

Any help appreciated.
Thanks
DS
johnwm (Programmer)
26 Nov 06 12:32
Look at the FileCopy statement in your VBHelp

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller

DSTR3 (TechnicalUser)
26 Nov 06 16:54
Ok Thanks, I'm doing this and it works fine.
FileCopy "c:\Proserv\DB\DellSat.mdb", "C:\ProServ\DB\BU.mdb"
    MsgBox "Completed"
A quick question though.  Does it Overwrite the exsisting file? How exactly does it work?
Thanks
DS
HughLerwill (Programmer)
26 Nov 06 17:11
The code you are using will not overwrite the existing file.

See the Name statement in VB6 Help

Name Statement
      

Renames a disk file, directory, or folder.

Syntax

Name oldpathname As newpathname

The Name statement syntax has these parts:

Part Description
oldpathname Required.String expression that specifies the existing file name and location — may include directory or folder, and drive.  
newpathname Required. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by newpathname can't already exist.


Remarks

The Name statement renames a file and moves it to a different directory or folder, if necessary. Name can move a file across drives, but it can only rename an existing directory or folder when both newpathname and oldpathname are located on the same drive. Name cannot create a new file, directory, or folder.

Using Name on an open file produces an error. You must close an open file before renaming it. Namearguments cannot include multiple-character (*) and single-character (?) wildcards.

HTH Hugh
HughLerwill (Programmer)
26 Nov 06 17:17
I could have given you misleading advise there. If is working as you have coded it be happy.

ref to the help for the Name statement could be useful though!

regards Hugh,
johnwm (Programmer)
26 Nov 06 17:57
Hugh
The help file I pointed to references the Name statement and the Kill statement, which should cover all points

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller

HughLerwill (Programmer)
26 Nov 06 18:21
Excuse me John
DSTR3 (TechnicalUser)
26 Nov 06 20:36
Thanks, It shouldn't be this hard.  I thought that by doing this it would just overwrite the mdb file.
Private Sub Command1_Click()
    FileCopy "c:\Proserv\DB\DellSat.mdb", "C:\ProServ\DB\BU.mdb"
    Unload Me
End
End Sub
DS
johnwm (Programmer)
27 Nov 06 2:31
I draw your attention again to FAQ222-2244 paragraph 8 and the Kill statement pointed out above.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller

Helpful Member!  Andrzejek (Programmer)
27 Nov 06 12:14
In my book, the best way to know is to try and see.

If FileCopy does not overwrite it, try:

CODE


Private Sub Command1_Click()
    Kill "C:\ProServ\DB\BU.mdb"
    FileCopy "c:\Proserv\DB\DellSat.mdb", _
         "C:\ProServ\DB\BU.mdb"
    Unload Me
    'End - bad idea, NEVER needed
End Sub

HTH

---- Andy
Golom (Programmer)
27 Nov 06 13:08
You could use a FileSystemObject (you need a reference to Microsoft Scripting Runtime)

CODE

With New FileSystemObject
   .CopyFile "c:\Proserv\DB\DellSat.mdb", "C:\ProServ\DB\BU.mdb", True
End With
Where thr "True" argument specifies over-writing of files.
BobRodes (Instructor)
27 Nov 06 13:36
Well, the FileCopy doc on the MSDN site fails to say explicitly that a file will be overwritten, although it implies it.  So, yes, DSTR3, your file should overwrite.  If you want to test it, and you can't do it by checking the mdb files for some reason, then create a couple of text files and play with them.

HTH

Bob
vbSun (Programmer)
27 Nov 06 22:18
Try adding the Date time stamp to the file name, if you want to create unique filenames and dont want to delete previous backups.

------------------------------------------
The faulty interface lies between the chair and the keyboard.

DSTR3 (TechnicalUser)
28 Nov 06 8:21
That sounds goog, how do you add a datestamp?
Thanks
DS
BobRodes (Instructor)
28 Nov 06 12:21
You just put today's date in the filename.
DSTR3 (TechnicalUser)
28 Nov 06 13:19
So it would be like this?
Date().Mdb
Thanks
DS
Andrzejek (Programmer)
28 Nov 06 13:44
I think what BobRodes suggests is put date and time as a part of your file name, but I don't think that's what you wanted to have.

You would:

CODE

FileCopy "c:\Proserv\DB\DellSat.mdb", _
   "C:\ProServ\DB\" & Date & ".mdb"
so you would end up with file
"C:\ProServ\DB\11282007.mdb"

You may also add a Time to your file name the same way.

But if you always want to have BU.mdb that will not work for you since you would have different file name every time you run this code.

---- Andy
DSTR3 (TechnicalUser)
28 Nov 06 16:25
Great!  Perfect!  Thanks
DS
BobRodes (Instructor)
28 Nov 06 19:28
Yes, what Andy is showing you is what I was suggesting.

Bob
DSTR3 (TechnicalUser)
28 Nov 06 21:06
Thank you as well.
DS

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close