locked
Moving Files through Access VBA RRS feed

  • Question

  • Hello,

    I hope this is more simple than my simple mind can see.

    I have two little .bmp files in locations on the C:\ I want to move them one at a time in a specific order if they exist in the folder. This effectively will switch the two pictures for the database background image.

    PrivateSub cmdMovebmp_OnClick()

    (Run Function) Movebmp1: If My.bmp in Folder A then move to Folder B Else (Run Function) Movebmp2

    (Run Function) Movebmp2: If My.bmp in Folder C then move to Folder A Else (Run Function) Movebmp3

    (Run Function) Movebmp3: If My.bmp in Folder B then move to Folder C Else DoNothing

    both files have the same name. If done in this order there will not be a conflict of same name files in the same folder. I can do this manually but I am not always the user and I wont always be there to manually do it.

    Thank you for your help!


    Chris Ward

    Friday, November 30, 2012 6:01 AM

Answers

  • Hello,

    I hope this is more simple than my simple mind can see.

    I have two little .bmp files in locations on the C:\ I want to move them one at a time in a specific order if they exist in the folder. This effectively will switch the two pictures for the database background image.

    PrivateSub cmdMovebmp_OnClick()

    (Run Function) Movebmp1: If My.bmp in Folder A then move to Folder B Else (Run Function) Movebmp2

    (Run Function) Movebmp2: If My.bmp in Folder C then move to Folder A Else (Run Function) Movebmp3

    (Run Function) Movebmp3: If My.bmp in Folder B then move to Folder C Else DoNothing

    both files have the same name. If done in this order there will not be a conflict of same name files in the same folder. I can do this manually but I am not always the user and I wont always be there to manually do it.

    Thank you for your help!

    Okay, one last question before I go to bed.

    The Name statement in VBA can be used to move a file from one location to another.  You'll find it in the VB Editor's online help.  The official purpose of the Name statement  -- Name "somefile" As "someotherfile" -- is to rename a file, but it will happily move a file if you specify a different folder path as part of the file name.

    I'm not completely following the logic you stated above (I told you I was sleepy) but in addition to checking whether the file exists that you want to move, you should also be prepared to deal with the possibility that it already exists in the target folder.  You might use inline error-handling with the Name statement to deal with both the absence of the source file and the presence of the target file, since the Name statement will raise an error in either circumstance.  However, my guess is that you want to deal with the presence of the target file differently than the absence of the source file.

    That may be confusing.  If it is, I'll try to expand on it tomorrow.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Proposed as answer by Dummy yoyo Friday, December 7, 2012 8:51 AM
    • Marked as answer by Dummy yoyo Monday, December 10, 2012 4:14 AM
    Friday, November 30, 2012 6:12 AM