Hello again,
Its been a while since I've asked a question, I've been learning steadily reading the How To's and the questions in this forum, as well as reading my Access VBA and Access bibles till they are now in tatters!.
I'm stuck with understanding the error handling process by VB6.5 (in particular for MSAccess 2003).
The following code is a test code only, so that I could understand things before I go on to something more meaty. It is probably the 5th incarnation or attempt and as you can see I have resorted to If..Then..Else and a SubFunction to try and handle this type of error. The error I'm referring to is the nasy Err 13 Data Type Mismatch error which occurs when I deliberately enter a non numeric character in the text box on the form. (The from has one command button and one text box) - Sub Command0_Click()
-
-
Dim aNumberbox As Double
-
Dim NotANumber As Variant
-
aNumberbox = 0
-
NotANumber = CVErr(13)
-
-
aNumberbox = CheckData(Me.Text1)
-
-
If IsError(aNumberbox) Then
-
Select Case aNumberbox
-
Case NotANumber
-
MsgBox "Error: not a number."
-
Case Else
-
MsgBox "Unknown Error."
-
End Select
-
Else
-
aNumberbox = Me.Text1
-
MsgBox ("You entered the number " & aNumberbox)
-
MsgBox ("Why not try it again?")
-
End If
-
End Sub
-
-
Function CheckData(aNumberbox As Integer) As Integer
-
Dim NotANumber As Integer
-
-
If Not IsNumeric(aNumberbox) Then
-
CheckData = NotANumber
-
End If
-
End Function
Despite trying to handle the error with a very simple error handle subroutine in my previous attempt: - Sub Command0_Click()
-
-
Dim aNumber As Double
-
On Error GoTo ErrorHandle
-
-
aNumber = CDbl(Me.Text1)
-
ExitHere:
-
MsgBox ("You entered the number " & aNumber)
-
MsgBox ("Why not try it again?")
-
-
-
ErrorHandle:
-
MsgBox ("Please enter a number.")
-
Resume ExitHere
-
End Sub
-
No matter what I do the Built-In Error Message (as unhelpful as they are :P) still occur.
Both sets of code of course break at the "aNumber = CDbl(Me.Text1)" line.
Would really appreciate it if anyone can help with this :)
JP
5 1784
Sorry but can't get what u want exactly
anyways a dirty solution is here
Sub Command0_Click( )
Dim aNumber As Double
On Error GoTo ErrorHandle
aNumber = CDbl(Me.Text1)
ExitHere:
MsgBox ("You entered the number " & aNumber)
MsgBox ("Why not try it again?")
Me.Text1.SetFoc us
Exit Sub
ErrorHandle:
MsgBox ("Please enter a number.")
Resume ExitHere
End Sub
Sorry but can't get what u want exactly
anyways a dirty solution is here
Sub Command0_Click( )
Dim aNumber As Double
On Error GoTo ErrorHandle
aNumber = CDbl(Me.Text1)
ExitHere:
MsgBox ("You entered the number " & aNumber)
MsgBox ("Why not try it again?")
Me.Text1.SetFoc us
Exit Sub
ErrorHandle:
MsgBox ("Please enter a number.")
Resume ExitHere
End Sub
Hello anuragshrivasta va
Thank you for your reply.
What I am trying to achieve is to stop the built-in error handling from occuring when the code encounters an error. The variable aNumber is set as a double to capture all digits (both whole and decimal) and the code will work fine with a number entered. However, enter a text character and the built-in error handler returns a type mismatch error, which is expected due to the type of data entered not being numeric.
I'm trying to stop the in-built mismatch error from reporting, and the mismatch error to be handled specifically by the ErrorHandle code block.
Can the mismatch type error be trapped and handled programmaticall y or will I have to respecify the data type of the anumber variable as perhaps a variant? If I have to change the data type to variant I will need to go with something similar to the first code block posted above using If...then...els e (which still doesn't work to stop the in-built error handling).
Thanks again.
JP
Hello anuragshrivasta va
Thank you for your reply.
What I am trying to achieve is to stop the built-in error handling from occuring when the code encounters an error. The variable aNumber is set as a double to capture all digits (both whole and decimal) and the code will work fine with a number entered. However, enter a text character and the built-in error handler returns a type mismatch error, which is expected due to the type of data entered not being numeric.
I'm trying to stop the in-built mismatch error from reporting, and the mismatch error to be handled specifically by the ErrorHandle code block.
Can the mismatch type error be trapped and handled programmaticall y or will I have to respecify the data type of the anumber variable as perhaps a variant? If I have to change the data type to variant I will need to go with something similar to the first code block posted above using If...then...els e (which still doesn't work to stop the in-built error handling).
Thanks again.
JP
Then u can simply check whetetehr the text enterd is numeric or not thru ISNumeric function
Just copy the following spurce of code before u chek
If Not IsNumeric(Me.Te xt1) Then
MsgBox "Sorry wrong entry"
Text1= ""
Text1.setfocus
Else
aNumberbox = CheckData(Me.Te xt1)
End If
Hello again anuragshrivasta va, :)
Thank you again for replying.
Thanks also for the code tweak. I've probably not asked the question correctly in the first place. I'm actually looking not for an actual solution but an understanding of how to deal with errrors within VB in a very general sense. The code at the top is just a test code to see how the whole error trapping and handling event is carried out, and to show that I have at least tried to do this on my own. I picked the dreaded error 13 data type mismatch to test as it seems to be the one that will most often cause issues if a user doesn't understand or makes an error with data entry. I guess where I've got myself very confused is from the different methodologies of error handling between different versions of VB (2003 - 2005 for instance) and looking at things like C++ etc.
I do appreciate you taking the time to respond and I apologise if I have wasted your time.
I am afraid I can't help u thru the whole exception handler methodology in VB.
Anyways what u can do is to create a new exception handler and may be write the following
ExceptionHandle r:
If Err.Number =13
MsgBox "Please enter the number correctly"
End if
If anything else u want to know please feel free to ask.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Erencans |
last post by:
Hi to all,
I want to error handling in ASP. But i think that ASP is not enough for
error handling. I have got two chance.
1. I can prapare an error page and control throught IIS.
2. I can use on error resume next.
For 1. This is a general handling. I want to handle local error. Maybe i do
special thing when error occured.
For 2. I have to write alot of lines code. I have to control every line.
|
by: Pete |
last post by:
I'm trying to improve my code so that when I open a recordset object,
I can absolutely guarantee it is closed and is set = Nothing. I have
read some old threads and they all say to use the functional
equivalent of the following code:
Public Sub CloseRecordset()
On Error GoTo Sub_Error
Dim rs As Recordset
rs.FindFirst "This Will Error"
|
by: Steve Richfield |
last post by:
My error handler works GREAT. However, VBA seems to have some
bugs/features that are causing it fits. The little snippet that I put
at the end of each routine looks like this:
Error_Handler:
If Error_Handler("<routine name>", Err) = acDataErrDisplay Then
On Error GoTo 0
Stop: Resume ' Press twice to view the problem.
|
by: Nathan Bloomfield |
last post by:
Hi there,
I am having difficulty with a piece of code which would work wonders
for my application if only the error trapping worked properly.
Basically, it works as follows:
- adds records from rsSource into rsDest
- if it finds a key violation then it deletes the current record from
rsDest and adds the new record from rsSource. This works perfectly -
but only for the first found duplicate record, it brings up the error
|
by: Keith |
last post by:
I have the following code in the On No Data event of a report:
****
On Error GoTo err_trap
MsgBox "No items matching criteria.", vbInformation, gcApplication
Cancel = True
err_trap:
If Err.Number = 2501 Then Exit Sub
| |
by: Thelma Lubkin |
last post by:
I use code extensively; I probably overuse it. But I've been using
error trapping very sparingly, and now I've been trapped by that.
A form that works for me on the system I'm using, apparently runs into
problems on the system where it will actually be used, and since I
used so little error-trapping it dies very ungracefully.
I will of course try to fix whatever is causing the error and add
error-trapping to the functions where the...
|
by: 47computers |
last post by:
Pretty new to PHP, I recently started learning about error trapping.
As of right now, I include the following into a page in my website:
-------BEGIN PASTE--------
error_reporting(E_ERROR | E_PARSE);
set_error_handler("SendErrorReport");
function SendErrorReport($errorNumber, $errorMessage, $errorFile,
$errorLine, $vars)
{
|
by: Jim Armstrong |
last post by:
Hello all -
This is driving me crazy. I have a table called tblClients - very
simple, has the following fields:
taxID (PK)
ClientName
SalesName
The main form of my application allows a user to select a client and
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge.
I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge.
I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |