Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56

    I have revised my code. I have added a new variant as the destination, and all the variants are working in the former msgboxes.
    I have msgboxes to keep track of what is happening. The last msgbox where I have Copy: to... Is not working and getting a compile error. I don't know why?

    Code:
    Private Sub cmdRenameCopy_Click()
    'Declare a variable as a FileDialog object.
        Dim fd As FileDialog
    
        'Create a FileDialog object as a File Picker dialog box.
        Set fd = Application.FileDialog(msoFileDialogOpen)
    
        'Declare a variable to contain the path
        'of each selected item. Even though the path is aString,
        'the variable must be a Variant because For Each...Next
        'routines only work with Variants and Objects.
        Dim OrigPath As Variant
        Dim OP As Variant
        Dim NNPath As Variant
        Dim NFPath As Variant
        
      
        'Use a With...End With block to reference the FileDialog object.
        With fd
    
            'Use the Show method to display the File Picker dialog box and return the user's action.
            'The user pressed the button.
        'If .Show = -1 Then
    
                'Step through each string in the FileDialogSelectedItems collection.
                'For Each vrtSelectedItem In .SelectedItems
                If fd.Show = True Then
                
            For Each OrigPath In fd.SelectedItems
            
         
               
               NNPath = Left(OrigPath, InStrRev(OrigPath, "\")) & NewName & Mid(OrigPath, InStrRev(OrigPath, "."))
                
                    MsgBox NNPath
                
                        Name OrigPath As NNPath
             
             NFPath = FullPath & "\" & NewName & Mid(NNPath, InStrRev(NNPath, "."))
       
                MsgBox NFPath
    
    
    
    
            MsgBox "Copy:" & _
            vbCrLf & "" & _
            vbCrLf & NNPath & _
            vbCrLf & "To" & _
            vbCrLf & NFPath & _
            vbOKCancel + vbQuestion, _
            "Accept or Cancel"
            
                 
    
                FileCopy NNPath, NFPath
    
                        MsgBox "File Copy Successful"
    
    Next
          
           
           ' Next
            End If
    
                    'vrtSelectedItem is a string that contains the path of each selected item.
                    'You can use any file I/O functions that you want to work with this path.
                    'This example displays the path in a message box.
                 
    
               ' Next vrtSelectedItem
            'The user pressed Cancel.
        'Else
            'End If
        End With
    
        'Set the object variable to nothing.
        Set fd = Nothing

  2. #17
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    Cancel that last question. This works: MsgBox "Copy:" & vbCrLf & "" & vbCrLf & NNPath & vbCrLf & "To: " & NFPath. Don't why the old version worked before, but adding my new variables stopped it working...

  3. #18
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    One last question on this thread, I promise. If I want to use the If MsgBox YesNo, how do I get the Yes response to continue and the no to execute another part of the code. Do I create a sub Name() for each process within the code to access it? I've looked for info on this and not finding answers. My Google search criteria is probably not accurately describing this process as I don't know what the process is called.

  4. #19
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    You want to use function form of MsgBox. You can set a variable then use the variable in If Then Else:
    intResponse = MsgBox("question", vbYesNo, "title")
    If intReponse = vbYes Then
    ...

    If only two responses allowed, can do:

    If MsgBox("question", vbYesNo, "title") = vbYes Then
    ...
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #20
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    OK, If = vbYes Then it will Run The code that follows, in this case change the name of the file and send. Now if the Name doesn't need to change ( = vbNo), and I still want to copy Original file to the destination using another Procedure.

    Code:
     If MsgBox("Rename:  " & Mid([OrigPath], InStrRev([OrigPath], "\") + 1) & _
                    vbCrLf & "As: " & NewName & Mid(OrigPath, InStrRev(OrigPath, ".")), vbYesNo + vbQuestion, "Accept or Cancel") = vbYes Then

    So, If vb=Yes the normal code will run here, but how do I get the following code to run if = vbNo? The following codes is after the first procedure that ends with "End If" I have tried numerous methods (Else, Else If)and keep getting compile errors.

    Code:
    End If
                        
                        
    
                    If MsgBox("Send File?& CrLf & OrigPath & CrLf & To: NPath", vbYesNo, "title") = vbYes Then
                        
                        
                        FileCopy OrigPath, NFPath
                        MsgBox "Your File Has been sent", vbOK
                        End If

  6. #21
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If MsgBox("Send File?" & CrLf & OrigPath & CrLf & "To: " & NPath, vbYesNo, "text you want here for title") = vbYes Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #22
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    Brilliant!!!! I had to put an "End" statement at the end of the first Procedure as it ran into the second Procedure, but all working the way I imagined.

    Thanks June7. This has been an extensive learning curve for me and I appreciate your help and guidance throughout this particular journey.

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

Similar Threads

  1. How to copy a file from one folder to another in vba
    By pkstormy in forum Code Repository
    Replies: 2
    Last Post: 09-20-2012, 05:32 PM
  2. Replies: 1
    Last Post: 06-26-2012, 03:06 AM
  3. Replies: 21
    Last Post: 01-24-2012, 06:21 PM
  4. folder locked after attaching a file
    By jimg972 in forum Access
    Replies: 0
    Last Post: 05-25-2011, 06:21 PM
  5. Copy file to folder
    By tpcervelo in forum Programming
    Replies: 11
    Last Post: 08-31-2010, 10:01 AM

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