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

    Runtime errors in Runtime Mode - My code works, but very messy

    I am testing my DB in runtime mode and am having problems with the code below. The code will execute and do what it is supposed to do which is check directories, rename a file and copy the file to another directory. But after it does all that, I get an error: "Execution of this application has stopped due to a run-time error", "The application can't continue and will be shut down." And shut down it does.



    I have tried several times to remove what seems to be excessive code, but nothing seems to work which will still allow the code to execute and not cause debugging issues . With all my trials and error in piecing together the code, I've ended up with the code below that is not very pretty, but works in my normal db mode. I am hoping someone can spot obvious problems and an early exit point .

    Code:
    Private Sub cmdFileNameSend_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= Original Path + New Name + the extension
               NNPath = Left(OrigPath, InStrRev(OrigPath, "\")) & NewName & Mid(OrigPath, InStrRev(OrigPath, "."))
                 
                 'NFPath = New Path + New Name + the Extension
                 NFPath = FullPath & "\" & NewName & Mid(NNPath, InStrRev(NNPath, "."))
          
                    'Notes:
                    ' NewName & Mid(OrigPath, InStrRev(OrigPath, ".")) = New file name + Original Extension
                        'Mid([OrigPath], InStrRev([OrigPath], "\") + 1) = Original Name + Original Extension
                            'MsgBox Left([NFPath], InStrRev([NFPath], "\") - 1)
                        
                        
                        
                     'Check if file exists
                
                   If Dir(NNPath) <> "" Then
                        
                    If MsgBox("Send File?" & vbCrLf & Mid([OrigPath], InStrRev([OrigPath], "\") + 1) & vbCrLf & "To: Sessions Folder", vbYesNo, "Send File") = vbYes Then
                        
                        
                        FileCopy OrigPath, FullPath & "\" & Mid([OrigPath], InStrRev([OrigPath], "\") + 1)
                        MsgBox "Your File Has been sent", vbOK
                        End
                        
                        
                        End If
                   ' MsgBox "File:  " & NewName & Mid(OrigPath, InStrRev(OrigPath, ".")) & "  Already Exists!!! Please check Your Files"
     
                        Else
     
                        'MsgBox "No Go!"
                               
    
                                'End  ' I added this so it will go no further
                                            'End If
                        
                        
                        
                        
                    
                    'Rename Msg
                 If MsgBox("Rename:  " & Mid([OrigPath], InStrRev([OrigPath], "\") + 1) & _
                    vbCrLf & "As: " & NewName & Mid(OrigPath, InStrRev(OrigPath, ".")), vbYesNo + vbQuestion, "Accept or Cancel") = vbYes Then
                    
                        'Rename Orininal file Name
                        Name OrigPath As NNPath
             
             
            
       
                'MsgBox NFPath
    
    
    
                    'Confirm Send File
            If MsgBox("Send File: " & Mid([NNPath], InStrRev([NNPath], "\") + 1) & _
            vbCrLf & vbCrLf & "" & "To: Sessions Folder ", vbYesNo + vbQuestion, "Send File") = vbYes Then
            
                        'Copy file with new name to Destination Folder
               FileCopy NNPath, NFPath
    
                        MsgBox "File Successfully Sent! "
                    End
                  
               End If
                    
                End
                        
    End
    End If
    
    
    
    End If
                        
                        
    
            
            End
    
    
    'Else
    
    
    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
    
    
    
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The error message does not include error number?
    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.

  3. #3
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    No Error Number. Msg below. The code does execute, so it seems as though it is something after file copy and success message and the End Sub that is causing the issue.

    Click image for larger version. 

Name:	Error.JPG 
Views:	15 
Size:	28.0 KB 
ID:	9198

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Well, without error code don't know if error handler would be possible or if would be even with error code.

    I have never converted db to run-time. If can't step debug or set up error handler, options seem limited.

    Could try running just some parts of the procedure and expanding it as it runs successfully. It will be tedious process but only thing I can suggest. So create a copy of the procedure with different name so you can copy/paste the code. Then in the original procedure remove everything between the last Dim and Set fd = Nothing lines. If that doesn't bomb in run-time then add a little more code just to open the file picker, test and continue.

    Good luck.
    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. #5
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    Finally got to the bottom of the Runtime errors. After fully dissecting and reconstructing the code, I removed all the "End" statements and it solved the issue. I also had the same issue with another macro and replaced the "End" statement with Exit Sub, which also solve that problem. Not sure why I didn't have errors when running full version of Access. Will see what happens when I test on a remote computer rather than my computer in Access Runtime \switch mode.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Ooops! Those End's should have hit me like a ton of bricks!! Yes, odd that the compiler didn't choke. Glad you figured it out.
    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. #7
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    I'm still not sure how I ended up with so many "Ends". I think I was just trying to get the code to stop/ exit rather than continue into the next routine, and since I didn't get any errors, it all seemed to be going well. I wish I could code with the elegance of a Shakespearean sonnet rather than the Dr Frankenstein's monster code I end up with - piecing things together.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2007 Runtime mode & Sharepoint list
    By PuJo in forum SharePoint
    Replies: 0
    Last Post: 07-31-2012, 05:16 PM
  2. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  3. Code works in full, fails in Runtime
    By stephenaa5 in forum Programming
    Replies: 3
    Last Post: 09-14-2010, 12:30 PM
  4. Problems with libraries in runtime mode
    By Fouti in forum Programming
    Replies: 1
    Last Post: 01-18-2010, 10:02 AM
  5. Need help w/ Forms/runtime mode
    By TechRetard in forum Access
    Replies: 1
    Last Post: 10-06-2009, 04:40 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