Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Feb 2002
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Build DOS copy to allow spaces in destination file (A2K)

    I am prompting my user for a string that will be used as the destination name in a file copy, as indicated in the code below. This works fine if the user does not include any spaces in the new file name. If they do, they get the DOS error "The syntax of the command is incorrect.". DOS requires surrounding quotes if there are spaces, ei: copy test.mdb "test number 2.mdb"

    I have been trying to edit a.WriteLine ("copy " & strDBPath & " " & CurrentDBDir & NewDBName & ".MDB") so it will enclose the CurrentDBDir & NewDBName & ".MDB" in quotes so DOS will accept it. I thought that I had handled a situation like this sucessfully in the past, but haven't been able to conquer it this time.

    Thanks,

    Randy

    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''
    <pre>strMsg = "Enter IMP Database Name, without .MDB extension (EI: MAY01IMP)"
    NewDBName = InputBox(Prompt:=strMsg, Title:="Build IMP Database", XPos:=2000, YPos:=2000)

    If NewDBName = "" Then
    Exit Function
    End If

    DoCmd.Hourglass True
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(CurrentDBDir & "CopyDupsMDB.bat", True)

    a.WriteLine ("copy " & strDBPath & " " & CurrentDBDir & NewDBName & ".MDB")
    a.WriteLine BatchCommand
    a.Close
    Call Shell(CurrentDBDir & "CopyDupsMDB.bat", 1)
    DoCmd.Hourglass False</pre>

    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''

  2. #2
    Star Lounger
    Join Date
    Feb 2002
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Build DOS copy to allow spaces in destination file (A2K)

    FYI: I learned from GHUDSON at http://www.forumco.com/jmhare/ that I could use chr(34) rather than using quote marks which solved my problem.

    Thanks,

    Randy

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington (Greater Manchester area)/Cheshire, UK
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Build DOS copy to allow spaces in destination file (A2K)

    Hi Randy,

    Try using an API call instead of shelling the copy command - its more effeciant and a lot faster.

    The code is as follows:

    Private Declare Function MsoCopyFileW Lib "mso9.dll" Alias "#882" (ByVal stOld As Long, ByVal stNew As Long, ByVal fFailIfItsThere As Long) As Long

    Function FCopyFile(ByVal stOld As String, ByVal stNew As String, Optional fFailIfItsThere As Boolean = True) As Integer

    FCopyFile = (MsoCopyFileW(StrPtr(stOld), StrPtr(stNew), Abs(fFailIfItsThere)) <> 0)

    End Function


    And then where you create and run the batch file, you can say the following instead:

    bRetVal=FCopyFile(strDBPath,CurrentDBDir & NewDBName & ".MDB")

    Hope this helps!

    James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •