Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Nothing wrong with filecopy - and your syntax looks OK, so sounds like a data or permissions problem



    On the basis the data is actually correct the only suggestion I can make is that whoever is running the code does not have the appropriate folder permissions. .ini files are windows initialisation files for example and your IT dept may prevent them from being created

    Have your tried manually copy/pasting?

    Have you tried stopping the code on the filecopy line, copying that line to the immediate window and running it (this is not the same as your comment in post #8)

    Other than that, I'm with Micron, you have a problem, but you are only sharing a couple of lines where you believe the problem exists. You may be right, or you may be wrong, but we don't know that. You wouldn't ring up your local garage and say 'my car won't start' and then not provide information such as there is fuel in the tank, the battery is charged, there are no loose wires, engine turns over but won't fire, or doesn't turn over, etc. If you don't see the point of providing that information, then it remains your problem

  2. #17
    Ellpee is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2013
    Posts
    80
    If my last came across as snarky, sorry -- wasn't my intention. I was trying to say it suddenly dawned on me that maybe I was barking up the wrong tree in the first place and needed to start over from square one: explain what I need VBA to do and let you guys tell me the easiest way to make it happen. All good?

  3. #18
    Ellpee is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2013
    Posts
    80
    Oh, yeah, and for Orange, with the few relevant lines in its own VBA module, it debugs and runs just fine, no error messages whatsoever, but nothing is coming out the other end of the pipe. This is true whether I use native FileCopy or FSO.CopyFile. As to the possibility of permissions problems, the guy who runs this is able to do the copy and paste thing manually without problems, so it would appear he has all the access privileges needed for this to work. Wondering if there's another way to do this using FSO and declaring the files as objects.....

  4. #19
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    Without knowing the sub name or how the variables are declared, I created a test sub.
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub btnDupeFile_Click()
        Dim sSourceFile As String
        Dim sDestinationFile As String
        Dim sFileExists As String
        
        sSourceFile = "D:\Forum\Misc\TestFile.ini"
        sDestinationFile = "D:\Forum\Misc\TestFile" & Me.ID_TRADE & ".ini"
        sFileExists = Dir(sDestinationFile)
        
        Debug.Print sSourceFile
        Debug.Print sDestinationFile
        Debug.Print "FileExists = " & sFileExists
        
        ' check if file already exists
        If Len(Trim(sFileExists)) > 0 Then
            MsgBox "File Already exists"
        Else
            FileCopy sSourceFile, sDestinationFile
        End If
    
    End Sub
    On first run, these are the debug prints:

    D:\Forum\Misc\desktop.ini
    D:\Forum\Misc\desktop12345.ini
    FileExists =

    And the file was copied with a new name.
    Then I ran it again. These are the debug prints:

    D:\Forum\Misc\desktop.ini
    D:\Forum\Misc\desktop12345.ini
    FileExists = desktop12345.ini

    Since the file already exists, the code skips creating the file again. Note that if the check to see if the file exists is not done, the file will overwrite the existing file without any notice.


    I also tried a text file "MTZTools.txt" and the copy was created ("MTZTools12345.txt").


    Maybe there is some corruption??

  5. #20
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Quote Originally Posted by Ellpee View Post
    Okay, well, I'm waving the white flag on this one. I started out explaining a simple thing I was trying to do, and have since posted many different things I tried without success. Lots of well-intended responses were heavy on "post more code" and "upload your database." My code, or the bit that is driving me nuts, is only a few lines trying to do a simple thing, so uploading much beyond that seems pointless. Just think of it as a tiny VBA procedure with only one purpose. So, back to square one. All I'm trying to get VBA to do is take an existing file on a network drive, make a copy, and save the copy under a different filename in exactly the same folder on exactly the same drive. It would appear the routes I tried -- FileCopy and FSO.CopyFile -- were not the way to go, so anybody who can suggest a different path that will get this done, let's hear it. Appreciate all the responses, but this is really in the category of "2 + 2 should yield 4, why doesn't it?" (Oh, but pulling it into a separate module did at least get rid of the error messages. Now it runs fine, no errors, but also no output file. Go figure.)
    So post what you have to do that. Someone can then copy it, modify what is needed to work on their system and try it out.
    Can you logon as that user and then try the code line by line?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #21
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    to complete your validation, you also need to check the validation of

    len(Dir(sSourceFile))<>0

  7. #22
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Ellpee,
    Your post did not come across as snarky to me. Your posts have each contained a fragment of info --as others have said- we're only seeing little pieces of the issue and little code or related info.

    Could be permissions?
    Could it be different drive mapping?
    Could be some form of corruption?
    Could be some network issue?

    However, if you and client can both do a copy and paste and get the file copied successfully that would indicate to me that the OS and non-Access utilities are working.
    If it is a permissions issue, I would expect to get an error message. You may have read permission, but not write permission- but that should give error.

    I would have included an error handler in Steve's code, but, he didn't get any error. As has been stated, this is pretty standard FileCopy stuff which may be pointing to some type of corruption as he asked.

    You find this link to Devhut a good reference, but it may not relate to your "possible corruption" issue.

  8. #23
    Ellpee is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2013
    Posts
    80
    Wow, thanks for all the interest. Overnight I had this hazy vision of a plan B. Create two object variables and set them as file1 and file2 (my template file and the new file I need to create). With FSO or otherwise, set the filename property of file2 to the new name (with full filepathname) I need. With FSO or otherwise, set the content property of file2 (filename2.text?) to the same as the content (filename1.text?) of file 1. Save file2. Does that strike anyone as a workable solution? I'm fuzzy on how to code all that but can probably figure it out if it's worth a try, and it bypasses the mystery of filecopy/copyfile.

    Please understand, I have limited ability to mess with client's stuff. Most of my work for them I log on remote, do what I can, and the guy there has to run it and test it. If things get really ugly I go to their offices and watch over his shoulder while he tests it, but things like stepping through code, no can do, risk of creating false records in their system.

  9. #24
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    it bypasses the mystery of filecopy/copyfile.
    maybe, maybe not - depends on why filecopy/copyfile isn't working

    if it works on your machine and not the clients, then you need to be looking at the client environment

  10. #25
    Ellpee is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2013
    Posts
    80
    Ta Da! Rewrote the code with no use of FileCopy or CopyFile. Open the template file, read its contents into memory, open (i.e., create) the target file, and download the contents from memory into the new file. Worked fine for me, awaiting results when customer runs another test. If it works for him, will come back here and put "SOLVED" to this one.

  11. #26
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Have you tried a simple DOS copy with Shell?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #27
    Ellpee is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2013
    Posts
    80
    Nope, if this one flops I'll look at that next. Thanks for the idea.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-05-2018, 10:56 AM
  2. Faster way to copy a file than FileCopy()
    By kdbailey in forum Access
    Replies: 10
    Last Post: 10-29-2015, 07:20 AM
  3. Replies: 1
    Last Post: 03-18-2014, 05:16 PM
  4. FileCopy
    By thescottsman92 in forum Access
    Replies: 1
    Last Post: 09-02-2013, 04:35 PM
  5. FileCopy Funtion
    By dccjr in forum Programming
    Replies: 2
    Last Post: 04-18-2013, 09:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums