I have a file that I would like to copy from a static location to one based on the value in a control (ChartNum) when the user clicks a button I'll provide for this purpose.
I know how to create the path string, but I don't know the MS command to do this.
The following Code will Copy Test.xls in the C:\Test\ Folder, to the C:\Stuff\ Folder, and Rename it to B1234.xls. - Dim ChartNum As String
-
-
ChartNum = "B1234"
-
-
FileCopy "C:\Test\Test.xls", "C:\Stuff\" & ChartNum & ".xls"
11 4008
The following Code will Copy Test.xls in the C:\Test\ Folder, to the C:\Stuff\ Folder, and Rename it to B1234.xls. - Dim ChartNum As String
-
-
ChartNum = "B1234"
-
-
FileCopy "C:\Test\Test.xls", "C:\Stuff\" & ChartNum & ".xls"
Oh that's great, ADezii!
But I forgot one thing: I want to first test whether the file is already there before I copy it.
How do I do that, too?
Oh, shoot--it turns out I'm not handling my MkDir commands at all correctly!
Here's what I have: - Function Public_Open_eAccount(strChartNum As String, strAccount As String)
-
On Error GoTo Err_Public_Open_eChart
-
-
Dim retVal As Variant
-
Dim strChartPath As String
-
Dim strAccountPath As String
-
Dim strFileName As String
-
Const conPath As String = "V:\Utilization Review\UR\eCharts\"
-
Const conFormSource As String = "V:\Utilization Review\UR\DATABASE\FORMS\"
-
-
' Need both parts of the path
-
If IsNull(strChartNum) Or IsNull(strAccount) Then Exit Function
-
-
' Make the path pieces
-
strChartPath = Replace(Replace(strChartNum, "\", ""), ",", "_")
-
strAccountPath = Replace(Replace(strAccountPath, "\", ""), ",", "_")
-
-
' Make the directory, if necessary
-
If Dir$(conPath & strChartPath, vbDirectory) = "" Then
-
MkDir (conPath & strChartPath & strAccountPath)
-
End If
-
-
' Copy forms into Account folder
-
strFileName = "18-1.DOC"
-
FileCopy conFormSource & strFileName, conPath & strChartPath & strAccountPath & strFileName
-
strFileName = "FAX COVER.DOT"
-
FileCopy conFormSource & strFileName, conPath & strChartPath & strAccountPath & strFileName
-
strFileName = "Medi-Cal UR Review.doc"
-
FileCopy conFormSource & strFileName, conPath & strChartPath & strAccountPath & strFileName
-
strFileName = "UR FORM.DOC"
-
FileCopy conFormSource & strFileName, conPath & strChartPath & strAccountPath & strFileName
-
-
' Display an Explorer window
-
retVal = Shell("Explorer.exe " & conPath & strChartPath & strAccountPath, vbNormalFocus)
-
-
Exit_Public_Open_eChart:
-
Exit Function
-
-
Err_Public_Open_eChart:
-
MsgBox Err.Description
-
Resume Exit_Public_Open_eChart
-
-
End Function
-
but it's creating only the path up to the chartnum, and it's not copying the files in (although that could very well be a function of not creating the path, too).
I minimized all my windows, and I just saw that all these copies of the forms are on my desktop, with variously mangled names! What???
Do you remember to add a \ in between strChartPath and strAccountPath? and a \ after strAccountPath?
When debugging remember to use either Debug.Print or msgbox to help you. For example, to make teh copy process clear: - strFileName = "UR FORM.DOC"
-
Msgbox "About to copy:" & vbnewline & _
-
"FROM: [" & conFormSource & strFileName & "]" & vbnewline & _
-
"TO: [" & conPath & strChartPath & strAccountPath & strFileName & "]"
-
FileCopy conFormSource & strFileName, conPath & strChartPath & strAccountPath & strFileName
Having good debugging skills will help you alot.
EDIT: Also remember that mkDir can only create one directory at a time. So to create the folder C:\Test\Folder, you must first ensure that C:\Test exists.
I have my own version I call MakeDir which will create any other folders needed to create the subfolder. I will include it here: - Public Function MakeDir(ByVal strPath As String) As Boolean
-
'creates a directory independent of whether the parent directory exists
-
'Code by TheSmileyOne
-
'Version 0.1
-
'Date 2010-05-19
-
-
'Known issues
-
'No error handling for cases such as network drives, with restricted permissions to create folders.
-
'No input validation
-
-
-
On Error GoTo err_Handler
-
-
'Check if rightmost char is a \
-
If Right(strPath, 1) = "\" Then
-
'Strip it
-
strPath = Left(strPath, Len(strPath) - 1)
-
End If
-
-
'Check if each individual directory exists, and if not, create it
-
Dim strSplitPath() As String
-
ReDim strSplitPath(UBound(Split(strPath, "\")))
-
strSplitPath = Split(strPath, "\")
-
Dim intI As Integer
-
Dim strCombined As String
-
For intI = 0 To UBound(strSplitPath)
-
If intI <> 0 Then strCombined = strCombined & "\"
-
-
strCombined = strCombined & strSplitPath(intI)
-
If Dir(strCombined, vbDirectory) = "" Then
-
MkDir strCombined
-
End If
-
-
-
-
Next
-
MakeDir = True
-
Exit Function
-
err_Handler:
-
MakeDir = False
-
MsgBox "Error " & Err.Number & " occured." & vbNewLine & Err.Description
-
-
End Function
NeoPa 32,556
Expert Mod 16PB
Sue,
Please try to keep a thread to a single (preferably the original) topic. This one's too messy now to split up.
We're happy to keep answering questions, but only one post can be flagged as the selected answer (ADezii's in this case I suggest), so your other questions need to be separated for the purposes of this site. Just a point to remember for what I hope are many more of your questions :-)
Oh, I apologize, NeoPa! At the time, these seemed like the same issue to me (because I was so wrapped up in it, I suppose!), but, of course, they are not.
I will certainly keep a closer watch on my posts in the future. I do know that a tight focus to a thread increases its usefulness, and this site is so useful that I want to help keep it that way.
@ADezii, that all seems to be working great. Thanks so much for your help!
(Next time, I'll try to stick to the subject! :D )
@TheSmileyCoder, I used your suggestions to correct how my MkDir was working, and that is working great now, too! Thanks!
You got 2 answers for the price of 1, nice deal sueb! (LOL).
NeoPa 32,556
Expert Mod 16PB
I know you're being as co-operative as you can Sue. I'm always happy to explain why we have the rules and you always appreciate that and learn for future postings :-)
PS. I should mention that, of course, Smiley's post was equally helpful and deserved a Best Answer too, but it was simply not a post that pertained to the original question (Hence, for this thread, I suggested ADezii's one). I hope no-one misunderstood my comment to be any form of favouritism, or even as denigrating Smiley's (excellent) post in any way.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul |
last post by:
Dear All,
I want to use web form to upload my file and copy the file to another
machine.
I can upload the file, but when I copy the file(file.CopyTo(".....", true))
to another machine(map...
|
by: Patrice Dargenton |
last post by:
Hello,
I have to convert an xml file to another xml file that is very similar, but
some content are different, and the names of some nodes are different. In
fact it's a response to a message :...
|
by: Jim Heavey |
last post by:
Hello, I have done some volunteer work for my club and develop a web site
in ASP.Net. I have the code working fine and now I am ready to move the
code up to their web hosting company. I have...
|
by: chiranjiv choudhary via .NET 247 |
last post by:
Can we have CodeBehind file in another server or same machine but diffrent location or directory
--------------------------------
From: chiranjiv choudhary
-----------------------
Posted by a...
|
by: Christopher Lusardi |
last post by:
If I want to copy one file to another how do I do that? I want to do
this even if the second file already exists.
Thanks,
Christopher Lusardi
|
by: LiveCycle |
last post by:
Hi,
I'm writing a web service, and, as part of its function, I want it to copy a
file from a remote server and place that file on the local web server under
another name. However, I always get...
|
by: rizwan6feb |
last post by:
Hello everybody. I need help on how to use copy function to copy file from one computer to another ( or any other way i can copy the file). The computers are on a local network.
|
by: wizdom |
last post by:
Help - change text on click - text has another onclick inside with php variables
----------
I think what I'm trying to do is simple.
I have a 2 buttons on a page. 1 button allows a thread of...
|
by: foss |
last post by:
hi all,
I am not able to copy file from a directory in the server to another directory.
Here,
the source is outside the web root directory and the destination is inside the web root directory. ...
|
by: ahmurad |
last post by:
Dear Brothers,
I am using a 'text file location' at my code to read the file contents- which is working fine in my local server. The web contents/php files and the specified txt file are at the...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |