Solved

execution of this application has stopped due to a run-time error

Posted on 2009-04-08
13
2,717 Views
Last Modified: 2013-11-29
Hi everybody,
I developed an application with access and when I tried to deploy the application with the access runtime it gives me the following error:

"Execution of this application has stopped due to a run-time error"
"The application can't continue an it will shut down."
It works fine in full version of access..
The following is the code:
The function  Activity_Enter() calls the StartRecordAtBeginning  and it(StartRecordAtBeginning) does executes fine but after that I get an error message  

"Execution of this application has stopped due to a run-time error"
"The application can't continue an it will shut down."

please help me...I'm working on this from last the 3 weeks but i could not fix the problem
Note: its working fine  in full version of access.
Private Sub Activity_Enter() 'this checks TargetID info
    If IsNull(TargetID) Then
        Call StartRecordAtBeginning
        End
    End If
End Sub
-----------------------------------------------------------------------------------------------------------------------
 
Sub StartRecordAtBeginning()
    If MsgBox("You have not yet entered the target ID#.  " & _
        "You must start data entry at the beginning.  " & _
        "Click 'Retry' to go back and enter the target " & _
        "ID#, or click 'Cancel' to erase this record without " & _
        "saving it.", vbRetryCancel, "Enter Target ID#") = vbCancel Then
            Call UndoRecordButton_Click
            End
    Else
        Screen.ActiveControl = ""
        TargetID.SetFocus
    End If
End Sub

Open in new window

0
Comment
Question by:shaggy2u
  • 6
  • 5
  • 2
13 Comments
 
LVL 28

Expert Comment

by:TextReport
ID: 24101409
Please put an error handler in each of your functions / sub routines. This should then advise what the error actually is as the error you are receiving is the standard runtime error when you haven't handled the error.

Below is a standard error handler I use.

Cheers, Andrew
Function MyOpenForm(pstrFormName As String)
On Error GoTo MyOpenForm_Error
 
    DoCmd.OpenForm pstrFormName
 
MyOpenForm_Exit:
    Exit Function
 
MyOpenForm_Error:
    Select Case Err
        Case 2102 ' Form Name Not Found
             MsgBox "Unknown Form " & Chr(39) & pstrFormName & Chr(39), vbCritical, "My App Name"
             Resume MyOpenForm_Exit
        Case Else
             Select Case MsgBox("An unexpected error has occurred in MyOpenForm" & vbCrLf & vbCrLf & _
                                "Error" & vbTab & "Description" & vbCrLf & _
                                Err & vbTab & Err.Description, vbCritical + vbAbortRetryIgnore, "Error")
                 Case vbAbort:  Resume MyOpenForm_Exit
                 Case vbRetry:  Resume
                 Case vbIgnore: Resume Next
             End Select
    End Select
End Function

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24103293
shaggy2u,

(No Points wanted)
When you add your error handler, be sure to change your "End" keywords to instead lead to the error handler, this way you exit greacfully, instead of "Ending" abruptly.
;-)

I am sure Andrew can help you with the specifics.
;-)

JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24103300
Andrew,

Nice error handler by the way.

(I am glad you and rockiroads decided to come back for a while)
;-)

Jeff
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 28

Expert Comment

by:TextReport
ID: 24104807
"(I am glad you and rockiroads decided to come back for a while)" Thanks

The only difference between this and what I normally use in production is the MsgBox on line 15 is normally a function that maintains an error log, handles ODBC error stacks and removed the Ignore option unless you are a developer.

Jeff, not sure what you mean about the END? The error handler always either returns to the Line that errors, the line after the error or the Exit label

Also forgot to mention when I copy and paste the block I always search and relance the olf function name, in this case MyOpenForm and replace it with the New function name, this then updates all my labels and normally the error message itself.

Finally when you receive an error you can do a CTRL-BREAK, click on Retry then DEBUG and using F8 step to the line that errors to check out what is going on.

Cheers, Andrew
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24106387
OK,

Usually when I need to get out of a sub, I use "Exit sub" (Not "End")

If State="NY" Then
  msgbox "NY"
else
    exit sub
end if

Instead when I use and error handler, I then use something like this:

On Error GoTo Err_cmpViewOffer_Click

If State="NY" Then
  msgbox "NY"
else
    GoTo Exit_cmpViewOffer_Click
end if


Exit_cmpViewOffer_Click:
    Exit Sub

Err_cmpViewOffer_Click:
    MsgBox "There was an error executing the command." _
    & vbCrLf & "Error " & Err.Number & ": " _
    & vbCrLf & Error, vbExclamation
    Resume Exit_cmpViewOffer_Click

So instead of just "End"-ing, you go to the error handler.

From what I have always learned you should only have 1 exit point in a sub.

If I have used this in the wrong context, or mis-understood the question, I apologize in advance.
;-)

Jeff


0
 
LVL 28

Expert Comment

by:TextReport
ID: 24106729
Hi Jeff, if you check the logic of the code then it always exits at line 7, the Exit Function. Once you are in teh error handler you either respond to the error with a RESUME, RESUME NEXT or RESUME ExitLabel
Cheers, Andrew
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24107107
OK,

I think I am just misunderstanding something then.

So I don't hijack this thread, I'll investigate this further on my own.

Thanks again.

Jeff
0
 

Author Comment

by:shaggy2u
ID: 24140032
I just removed END statement before else ..and its working fine now in the runtime
Thanks
0
 
LVL 28

Expert Comment

by:TextReport
ID: 24159567
The END statement should not have caused the Runtime error you were experiencing as it is acceptable and should have terminated the procedure as per the note below from the Access help file.

"End Terminates execution immediately. Never required by itself but may be placed anywhere in a procedure to end code execution, close files opened with the Open statement and to clear variables. "

Please note you MUST have a decent error handler in ALL your sub routines and functions if you do not you will get strage results and poor experiences for your users. Please note you can get away not putting in an error handler in a function / sub if it is called by another function / sub that has an error handler, however, this is then harder to determine the exact location of the error.

Cheers, Andrew
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24163918
Andrew,

This was what I was referring to in my post about using "END".
I had alway been taught to use "Exit Sub" not "End".

As for the "technical" differences between them, ...I am not sure, but I have never used "End", I always use Exit Sub, and never had a problem like the described here.
So when I saw "end", I thought: "That seems odd, just send it to the Error Handler, (Or use Exit sub)
It is rare that I see "End" used in Access code submitted here either.

With Service Packs/Hotfixes and office updates all possibly playing a role, it is difficult for me, at least, to say why eliminating "End" solved the issue.

But I do know that we have all seen code here that "Worked fine" in previous Access versions fail in newer vesions of Access.
;-)
(undeclared variables in Access 2003-2007 are one example)

Thanks again, for your comments on the Error Handling.
Again I will research this on my own and see if I understand your post correctly.
;-)

Jeff
0
 
LVL 28

Expert Comment

by:TextReport
ID: 24165584
Hi Jeff, sorry I misread your END comment as being directed to the example error handler rather then the END in the original post.
Cheers, Andrew
0
 

Accepted Solution

by:
shaggy2u earned 0 total points
ID: 24189794
But the truth is my code worked fine after deleting END statement..
0
 
LVL 28

Expert Comment

by:TextReport
ID: 24191307
"But the truth is my code worked fine after deleting END statement.." no one is doubting you but to run code without error handlers, especially in a runtime environment, is a THOU SHALL NOT as far as developers are concerned. The reason for this is the abrupt ending if an error occurs and you error handler will be able to advise what is going on.
Cheers, Andrew
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question