Solved

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

Posted on 2009-04-08
13
2,659 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
Comment Utility
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
Comment Utility
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
Comment Utility
Andrew,

Nice error handler by the way.

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

Jeff
0
 
LVL 28

Expert Comment

by:TextReport
Comment Utility
"(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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
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
Comment Utility
I just removed END statement before else ..and its working fine now in the runtime
Thanks
0
 
LVL 28

Expert Comment

by:TextReport
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
But the truth is my code worked fine after deleting END statement..
0
 
LVL 28

Expert Comment

by:TextReport
Comment Utility
"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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now