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

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

shaggy2uAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
shaggy2uConnect With a Mentor Author Commented:
But the truth is my code worked fine after deleting END statement..
0
 
TextReportCommented:
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
 
Jeffrey CoachmanMIS LiasonCommented:
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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
Jeffrey CoachmanMIS LiasonCommented:
Andrew,

Nice error handler by the way.

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

Jeff
0
 
TextReportCommented:
"(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
 
Jeffrey CoachmanMIS LiasonCommented:
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
 
TextReportCommented:
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
 
Jeffrey CoachmanMIS LiasonCommented:
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
 
shaggy2uAuthor Commented:
I just removed END statement before else ..and its working fine now in the runtime
Thanks
0
 
TextReportCommented:
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
 
Jeffrey CoachmanMIS LiasonCommented:
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
 
TextReportCommented:
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
 
TextReportCommented:
"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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.