Dear friends,
I am using the following code in the afterupdate event of my textbox: - If Not IsDate([MyTextBox]) Then
-
MsgBox "Invalid date!"
-
Else
-
'do nothing, date is OK
-
End If
My problem is that if the user entered false date such as 15-15-2009
The Ms Access error message is displayed "The value you entered is not valid for this field" instead of my own message which is "invalid date!"
How this problem can be solved?
Any help will be highly appreciated
Disregard my last post. I tested this myself and found myself surprised and a little annoyed at Microsoft, it appears that a form validation happens before the field validation which means that you need to catch this on the Form_Error, sorry for the confusion, but my logic is still correct about before and after updates, the difference is that Form_Error happens before either.
Here is the code you will need to properly catch this: - Private Sub Form_Error(DataErr As Integer, Response As Integer)
-
Select Case DataErr
-
Case 2113
-
If Me.ActiveControl.Name = "MyTextBox" Then
-
MsgBox "Invalid date!"
-
Response = acDataErrContinue
-
End If
-
End Select
-
End Sub
This code triggers on Form_Error, it then checks the error number, which in this case is 2113 which means an invalid entry in a field, then it will check that we are on "MyTextBox", if it is it will give your error message and then continue on.
Also, please make sure the before and after update subs are gone so that you aren't replicating effort.
If you have any questions don't hesitate to ask.
-AJ
7 3496
If this is a bound field to a date field in your table, then the reason you are getting the error is because you are allowing the update to the table to take place and then checking it afterupdate, so you are getting access's error because it supersedes your check. If you want to catch this before it tries to save to your table you need to do this on beforeupdate.
Like this: - Private Sub MyTextBox_BeforeUpdate(Cancel As Integer)
-
If Not IsDate([MyTextBox]) Then
-
MsgBox "Invalid date!"
-
Cancel = True
-
Else
-
'do nothing, date is OK
-
End If
-
End Sub
Let me know if this works for you, or if you need me to clarify the issue further.
-AJ
NeoPa 32,556
Expert Mod 16PB
AJ is Spot On (of course). I would simply add that the Else part of the If is not necessary in this instance, and should probably be omitted.
Welcome to Bytes!
Thanks ajalwaysus for your hard effort.
But I'm still having the same problem
Remark : regarding your point whether my text box is bound field to a date field in my table the answer is yes
I need to see the code, as this should work without issue. Please copy and paste your code as it appears in your DB to this thread and let me take a look, also make sure you take out the afterupdate sub as it is no longer needed.
-AJ
Disregard my last post. I tested this myself and found myself surprised and a little annoyed at Microsoft, it appears that a form validation happens before the field validation which means that you need to catch this on the Form_Error, sorry for the confusion, but my logic is still correct about before and after updates, the difference is that Form_Error happens before either.
Here is the code you will need to properly catch this: - Private Sub Form_Error(DataErr As Integer, Response As Integer)
-
Select Case DataErr
-
Case 2113
-
If Me.ActiveControl.Name = "MyTextBox" Then
-
MsgBox "Invalid date!"
-
Response = acDataErrContinue
-
End If
-
End Select
-
End Sub
This code triggers on Form_Error, it then checks the error number, which in this case is 2113 which means an invalid entry in a field, then it will check that we are on "MyTextBox", if it is it will give your error message and then continue on.
Also, please make sure the before and after update subs are gone so that you aren't replicating effort.
If you have any questions don't hesitate to ask.
-AJ
NeoPa 32,556
Expert Mod 16PB
Well, I've learned something tonight. Good one AJ.
Dear ajalwaysus ,
Thanks and God bless you
I am much obliged to you
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Darren |
last post by:
I had to restore my server from backup. When I did, I
could no longer access any asp pages on my web server.
The error says HTTP 500 Internal Server Error. I have
turned off friendly HTTP error...
|
by: dmiller23462 |
last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript
but my end result is I need two text boxes to stay hidden until a
particular option is selected....I've cobbled together the...
|
by: James |
last post by:
Hello,
I have a RequiredFieldValidator for several textbox controls on a
form. Here's an example with the RequiredFieldValidator.
EnableClientScript, Enabled, and Visible are set to true for...
|
by: panche |
last post by:
I'm developing a fairly simple user control that has two textboxes for
date/time entry (a from date/time and a to date/time). One of my
requirements is that there should be no button that sets...
|
by: Rob R. Ainscough |
last post by:
VS 2005 I have:
ClickOnce deployment
User's that hate and or don't want to use an IE Client (don't blame them)
I don't see how ASPX web pages are going to survive? With .NET 2.0 and
clickonce...
|
by: c676228 |
last post by:
Hi,
I have several user controls like email, phone,ssn etc. each has it's own
validation message in its user control already.
When I bring all those user controls in an aspx page, I would like to...
|
by: Pacer Dawn |
last post by:
I have a web control that takes a date input. There are two types of
validation I want to do on this:
1) validate that the date input is in the proper format, and display a
message if otherwise...
|
by: rn5a |
last post by:
The different Validation controls like RequiredFieldValidator,
RangeValidator etc. have a property named Display. This property can
have 3 values - Dynamic, Static & None. What's the difference...
|
by: phil67b |
last post by:
Hello everybody,
I have a page rech.php where I'm doing a multi-criteria research Ex.
choose your car model, choose your country.
After validation of my form, on the same page, the lines will be...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
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: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
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: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
| |