Copy jpg files from one folder to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CD Tom
    Contributor
    • Feb 2009
    • 495

    Copy jpg files from one folder to another

    I've got a folder on my c: drive that has about 6 thousand photos. The photos have a file name of like 00239.jpg which matches a member number in my database. I want to move some of the photos to another folder on the c: drive. I have a table that is created with the photos I want to move. That table has the member number in it like 00239 How do I go about doing this in my program?
    My mind has gone blank in how to do this.

    Thanks for any help.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    This is not a code writing service but if you post the code you've tried along with a description of the problem, we can help guide you to a solution.

    As a hint, you can use the FileCopy function in VBA.

    Comment

    • CD Tom
      Contributor
      • Feb 2009
      • 495

      #3
      I didn't mean to have someone write the code just point me the right direction which you did. However I've run into a funny problem here's the code
      Code:
      Private Sub CmdExportApp_Click()
      On Error GoTo Err_CmdExportApp_Click
          Dim db As Database
          Dim RSPhoto As DAO.recordset
          Set db = CurrentDb()
          
          vtable = "MbrsTOCSV"
          apppathx = ("C:\Membership" + "\" + "App Data\" + "NewMBRS.csv")
          DoCmd.TransferText acExportDelim, , vtable, apppathx, True
          
          strFolderName = "C:\Membership\App Data"
          Kill strFolderName + "\" & "*.*"
          strsql = "select * from CurrentPhotos"
          Set RSPhoto = db.OpenRecordset(strsql)
          Do While Not RSPhoto
              vcp = RSPhoto("TPhoto")
              vcp = vcp & ".JPG"
              Sourcefile = ("C:\B4aExamples" + "\" + "TCGC JPG\" + "" & vcp & "")
              Destinationfile = ("C:\Membership" + "\" + "Export Data\" + "" & vcp & "")
              FileCopy Sourcefile, Destinationfile
          RSPhoto.MoveNext
          Loop
      
          Call GetZip
          
      Exit_CmdExportApp_Click:
          Exit Sub
      
      Err_CmdExportApp_Click:
          MsgBox Err.Description
          Resume Exit_CmdExportApp_Click
          
      End Sub
      the program runs fine for about four copies then access stops working and closes and restarts.
      It will stop on the Do While Not RSPhoto no error messages access just stops working and restarts itself. Any ideas what could be causing this?

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        That's weird that it would just stop without an error. Does it always stop on the fourth file? Maybe the filename is incorrect or something. Try stepping through the code to see which line it's stopping on.

        Comment

        • Stewart Ross
          Recognized Expert Moderator Specialist
          • Feb 2008
          • 2545

          #5
          I'm puzzled by the Access crash too, but I notice that you appear to have incorrectly defined line 15 and wonder if this has something to do with it. Surely this line should be

          Code:
          Do While Not RSPhoto.EOF
          rather than
          Code:
          Do While Not RSPhoto
          -Stewart

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            That is strange... you might want to make sure you are starting with the first record before entering your loop.
            Code:
            RSPhoto.MoveFirst

            Comment

            • CD Tom
              Contributor
              • Feb 2009
              • 495

              #7
              Well that was it not having the .eof at the end made all the difference, don't know why I didn't notice that.
              Thanks for all your help.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32661

                #8
                Line #15 should probably be checking RSPhoto.EOF rather than RSPhoto itself Tom. That said, I don't follow why it would crash as you describe.

                The only idea I have is that FileCopy may be asynchronous, but I seriously doubt that.

                If the .EOF doesn't fix it then try adding DoEvents after line #21.

                PS. Ooops. I must remember to refresh my pages when I'm busy with work :-(
                I'll set the Best Answer for you.
                Last edited by NeoPa; Jan 18 '13, 12:20 AM. Reason: Added PS.

                Comment

                Working...