Solved

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

Posted on 2009-04-08
13
2,798 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

627 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