I have set up customized error messages for a form using the
OnError event of the form's vba coding.
However, when the error is trigerred by a command button, the OnError event is not called and you have to manually code that error on the On Error GoTo statement of the command button.
My question is this, how can you recall the coding you made on the OnError event of the form, into the On Error Goto of the command button.
Example: - Private Sub Form_OnError(DataErr As Integer, Response As Integer)
-
-
If DataErr = 3317 Then
-
MsgBox "This is a customized error message"
-
Reponse = DataErrContinue
-
ElseIf DataErr = 3314 Then
-
MsgBox "This is another customized error message"
-
Reponse = DataErrContinue
-
Else
-
MsgBox Err.Description
-
Reponse = DataErrContinue
-
End If
-
-
End Sub
-
-
Private Sub cmdSave_Click()
-
On Error GoTo ErrorHandler
-
-
Docmd.RunCommand acCmdSaveRecord
-
-
ExitSub:
-
ExitSub
-
-
ErrorHandler:
-
'statement to recall the OnError event of the form
-
Response = DataErrContinue
-
Resume ExitSub
-
-
End Sub
14 10306
I have set up customized error messages for a form using the
OnError event of the form's vba coding.
However, when the error is trigerred by a command button, the OnError event is not called and you have to manually code that error on the On Error GoTo statement of the command button.
My question is this, how can you recall the coding you made on the OnError event of the form, into the On Error Goto of the command button.
Example: - Private Sub Form_OnError(DataErr As Integer, Response As Integer)
-
-
If DataErr = 3317 Then
-
MsgBox "This is a customized error message"
-
Reponse = DataErrContinue
-
ElseIf DataErr = 3314 Then
-
MsgBox "This is another customized error message"
-
Reponse = DataErrContinue
-
Else
-
MsgBox Err.Description
-
Reponse = DataErrContinue
-
End If
-
-
End Sub
-
-
Private Sub cmdSave_Click()
-
On Error GoTo ErrorHandler
-
-
Docmd.RunCommand acCmdSaveRecord
-
-
ExitSub:
-
ExitSub
-
-
ErrorHandler:
-
'statement to recall the OnError event of the form
-
Response = DataErrContinue
-
Resume ExitSub
-
-
End Sub
To Call another Sub-Routine, say the Click() Event of the Command6 Button, you would use the syntax Call Command6_Click. To the best of my knowledge, you cannot call a built-in Routine in this same fashion. Since the Form's Error() Event was never triggered, you can't expect to fire it from a non Form related Error. The Arguments DataErr and Response would also have no meaning in that context. What you can do is have a Global Error Handling Procedure which has all Errors passed to it as Arguments. All Error Handling logic for the Application is handled here, and the appropriate actions taken depending on the specific Errors. Hope this helps.
Assuming this is VBA and not VB6, one problem I see here is the very name of your sub!
Private Sub Form_OnError(DataErr As Integer, Response As Integer)
While it's called the OnError event in the form's Property Box, the sub it actually generates is
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Unless this is something that's changed with the latest verison of Access, and I wouldn't think it is (but with Micro$oft you never know) maybe this is why the form level error handling isn't working.
Linq ;0)>
Assuming this is VBA and not VB6, one problem I see here is the very name of your sub!
Private Sub Form_OnError(DataErr As Integer, Response As Integer)
While it's called the OnError event in the form's Property Box, the sub it actually generates is
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Unless this is something that's changed with the latest verison of Access, and I wouldn't think it is (but with Micro$oft you never know) maybe this is why the form level error handling isn't working.
Linq ;0)>
Hello ling:
Since the Error is being triggered from the Click() Event of a Command Button, the Form's Error() Event will never fire. The Error() Event will fire for Microsoft Jet Database Engine errors, but not run-time errors in Visual Basic or errors from ADO. Just some useless information.
No information is useless; well, almost none!
Linq ;0)>
Assuming this is VBA and not VB6, one problem I see here is the very name of your sub!
Private Sub Form_OnError(DataErr As Integer, Response As Integer)
While it's called the OnError event in the form's Property Box, the sub it actually generates is
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Unless this is something that's changed with the latest verison of Access, and I wouldn't think it is (but with Micro$oft you never know) maybe this is why the form level error handling isn't working.
Linq ;0)>
oh yes, sorry. i did mean the FOmr_Error. :)
To Call another Sub-Routine, say the Click() Event of the Command6 Button, you would use the syntax Call Command6_Click. To the best of my knowledge, you cannot call a built-in Routine in this same fashion. Since the Form's Error() Event was never triggered, you can't expect to fire it from a non Form related Error. The Arguments DataErr and Response would also have no meaning in that context. What you can do is have a Global Error Handling Procedure which has all Errors passed to it as Arguments. All Error Handling logic for the Application is handled here, and the appropriate actions taken depending on the specific Errors. Hope this helps.
can you tell me how to make a global error handling procedure?
can you tell me how to make a global error handling procedure?
In its simplest case, a Global Error Handler is nothing more than a Public Function or Sub-Routine which accepts certain Error Arguments passed to it from Local Procedures. In some cases, and with specific Errors, the probelms actually causing the Errors can be fixed in the Global Handler. Below, please find a simple Global Error Handler: - Public Sub HandleAllErrors(lngErrorNumber As Long, strErrorDescription As String, strErrorSource As String)
-
Dim Msg As String
-
Msg = "Error Number: " & lngErrorNumber & vbCrLf & _
-
"Error Description: " & strErrorDescription & vbCrLf & _
-
"Error Source: " & strErrorSource
-
-
Select Case lngErrorNumber
-
Case 1
-
Case 11 'Division by 0
-
MsgBox "Somewhere in your calculations you divided by 0", vbExclamation, "Division by Zerro"
-
Case 76 'Path not Found
-
MsgBox "The Path you are trying to create or access does not exist", vbExclamation, "Path Not Found"
-
Case 234
-
Case 888
-
Case Else 'Unhandled Errors
-
MsgBox Msg, vbExclamation, "Global Error Handler"
-
End Select
To direct Error Codes to the Handler: - Private Sub Command42_Click()
-
On Error GoTo Err_Command42_Click
-
-
'Will cause a Division by 0 Error
-
Dim X
-
X = 123 / 0
-
-
Exit_Command42_Click:
-
Exit Sub
-
-
Err_Command42_Click:
-
Call HandleAllErrors(Err.Number, Err.Description, Err.Source)
-
Resume Exit_Command42_Click
-
End Sub
In its simplest case, a Global Error Handler is nothing more than a Public Function or Sub-Routine which accepts certain Error Arguments passed to it from Local Procedures. In some cases, and with specific Errors, the probelms actually causing the Errors can be fixed in the Global Handler. Below, please find a simple Global Error Handler: - Public Sub HandleAllErrors(lngErrorNumber As Long, strErrorDescription As String, strErrorSource As String)
-
Dim Msg As String
-
Msg = "Error Number: " & lngErrorNumber & vbCrLf & _
-
"Error Description: " & strErrorDescription & vbCrLf & _
-
"Error Source: " & strErrorSource
-
-
Select Case lngErrorNumber
-
Case 1
-
Case 11 'Division by 0
-
MsgBox "Somewhere in your calculations you divided by 0", vbExclamation, "Division by Zerro"
-
Case 76 'Path not Found
-
MsgBox "The Path you are trying to create or access does not exist", vbExclamation, "Path Not Found"
-
Case 234
-
Case 888
-
Case Else 'Unhandled Errors
-
MsgBox Msg, vbExclamation, "Global Error Handler"
-
End Select
To direct Error Codes to the Handler: - Private Sub Command42_Click()
-
On Error GoTo Err_Command42_Click
-
-
'Will cause a Division by 0 Error
-
Dim X
-
X = 123 / 0
-
-
Exit_Command42_Click:
-
Exit Sub
-
-
Err_Command42_Click:
-
Call HandleAllErrors(Err.Number, Err.Description, Err.Source)
-
Resume Exit_Command42_Click
-
End Sub
wow!!! that's cool. makes sense to me.
one more thing, where do i save this Public sub?
do i save this in the forms vba?
what If i want to be able to call this from the other forms as well?
htnks in advance
wow!!! that's cool. makes sense to me.
one more thing, where do i save this Public sub?
do i save this in the forms vba?
what If i want to be able to call this from the other forms as well?
htnks in advance
hi there! u can save the sub anywhere u like, wether in a class or in a form...
u call it like this: lets say u are in form2 then the sub is in form1:
form1.errorHandler([parameters])
hope this helps....
enjoy coding
wow!!! that's cool. makes sense to me.
one more thing, where do i save this Public sub?
do i save this in the forms vba?
what If i want to be able to call this from the other forms as well?
htnks in advance
As a global error handler it should be in a separate module.
As a global error handler it should be in a separate module.
I tried saving it in a class module but i get an error:
"Compile Error:
Expected Variable or procedure, not module"
how do i do this?
I tried saving it in a class module but i get an error:
"Compile Error:
Expected Variable or procedure, not module"
how do i do this?
Not a class module just an ordinary module.
Not a class module just an ordinary module.
thanks mary. i'll try that.
is this regular module the one created when i click Insert -> Module?
isn't this module going to be in the forms vba only?
how can i use it in other forms' vba?
thanks mary. i'll try that.
is this regular module the one created when i click Insert -> Module?
isn't this module going to be in the forms vba only?
how can i use it in other forms' vba?
If you use it as Insert - Module, then its independent of any one form and can be called by all forms.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Asapi |
last post by:
1. Are linkage convention and calling convention referring to the same
thing?
2. Does calling convention differ between languages C and C++?
3. How does calling convention differ between...
|
by: Muthu |
last post by:
I've read calling conventions to be the order(reverse or forward) in
which the parameters are being read & understood by compilers.
For ex. the following function.
int Add(int p1, int p2, int...
|
by: Klaus Friese |
last post by:
Hi,
i'm currently working on a plugin for Adobe InDesign and i have some
problems with that. I'm not really a c++ guru, maybe somebody here has
an idea how to solve this.
The plugin is...
|
by: Nick Flandry |
last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my
development environment (Win2K server running IIS 5) and a test environment (also Win2K server
running IIS...
|
by: Mike |
last post by:
Timeout Calling Web Service
I am calling a .NET 1.1 web service from an aspx page. The web service can
take several minutes to complete its tasks before returning a message to the
aspx page.
...
|
by: Geler |
last post by:
A theoretical question: Sorry if its a beginner question.
Here is a quote from the MSDN explaning the C/C++ calling convention.. It
demonstrates that the calling function is responsible to clean...
|
by: teju |
last post by:
hi,
i am trying 2 merge 2 projects into one project.One project is using c
language and the other one is using c++ code.
both are working very fine independently.But now i need to merge both...
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
I have a C# logging assembly with a static constructor and methods that is
called from another C# Assembly that is used as a COM interface for a VB6
Application. Ideally I need to build a file...
|
by: sulekhasweety |
last post by:
Hi,
the following is the definition for calling convention ,which I have
seen in a text book, can anyone give a more detailed explanation in
terms of ANSI - C
"the requirements that a...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |