My need is to check an input date, like 01/10/492 and be able to recognize it is not correct date, and then enter a default date in that location. I have read and tried a few things, and am presently trying this -
IIf(DateValue([Field2])=[#error],"01/01/1990",[field2])
-
the idea being if the datevalue function returned error, (it shows #error as return on my query, ) , then I would enter default date, and if not would maintain the same data by using the false argument.
Thank you for any help, I am looking for a user group, cause I want to learn but I am finding the reading very hard.
Ken
11 2814
Hi, Ken.
I'm very unsure it is even possible to catch an error within expression.
I would like to recommend you to do it via VBA.
Just write the following simple function in a public code module: -
Public Function ConvertDate(varInput As Variant) As Date
-
-
On Error GoTo ConvertionFailed
-
ConvertDate=......<date function you use>
-
Exit Function
-
ConvertionFailed:
-
ConvertDate = #1/1/1990#
-
-
End Function
-
Then replace the whole IIf() expression in your query with -
ConvertDate([The Name of date field you are working with])
-
P.S. Are you still working on that problem ?
My need is to check an input date, like 01/10/492 and be able to recognize it is not correct date, and then enter a default date in that location. I have read and tried a few things, and am presently trying this
(CODE)
IIf(DateValue([Field2])=[#error],"01/01/1990",[field2])
(/CODE)
the idea being if the datevalue function returned error, (it shows #error as return on my query, ) , then I would enter default date, and if not would maintain the same data by using the false argument.
Thank you for any help, I am looking for a user group, cause I want to learn but I am finding the reading very hard.
Ken
If the Input Value is being entered into a Form Field named txtDate, then: - Private Sub txtDate_AfterUpdate()
-
If IsNull(Me![txtDate]) Then
-
Exit Sub
-
ElseIf Not IsDate(Me![txtDate]) Then
-
Me![txtDate] = #1/1/1990#
-
Else
-
Me![txtDate] = Me![txtDate]
-
End If
-
End Sub
Hi, Ken.
I'm very unsure it is even possible to catch an error within expression.
I would like to recommend you to do it via VBA.
Just write the following simple function in a public code module: -
Public Function ConvertDate(varInput As Variant) As Date
-
-
On Error GoTo ConvertionFailed
-
ConvertDate=......<date function you use>
-
Exit Function
-
ConvertionFailed:
-
ConvertDate = #1/1/1990#
-
-
End Function
-
-
-
Then replace the whole IIf() expression in your query with -
ConvertDate([The Name of date field you are working with])
-
P.S. Are you still working on that problem ?
Yes I am still working. I took your advice,and replaced the null and items that evaluatied <0 to get to this last type of input error. Believe it or not, the CDate returns a valid date, for things like 5/5/392. This causes me issues with the person using this data. I will try your VB solution.
My main problem is, I want to convert the table column to Date/Time data type. and when I try it, if there is a mismatch at all, it threatens to remove any row with a bad date. So I am trying to change all the date (in text format) with your help.
Yes I am still working. I took your advice,and replaced the null and items that evaluatied <0 to get to this last type of input error. Believe it or not, the CDate returns a valid date, for things like 5/5/392. This causes me issues with the person using this data. I will try your VB solution.
My main problem is, I want to convert the table column to Date/Time data type. and when I try it, if there is a mismatch at all, it threatens to remove any row with a bad date. So I am trying to change all the date (in text format) with your help.
Ok Fish, I ran the function, and it ran ok, but it actually changed all dates to the default date, so It thinks all are errors I guess.
I put in CDate(Field2) which is the field containing the dates. Following are dates on the test list.
ID Field2 Field3
1 01/01/1990 00:00 AM
2 7/9/2003 10:15:30 PM
3 7 /9/2003 09:15 AM
4 5/5/192 01:25:15 PM
5 01/01/1990 08:15
6 01/01/1990 00:00 AM
7 8/5/07 00:00 AM
8 10/03/200 07:15
9 03/35/44 08:15
10 3/17/40 00:00 AM
all these ended up with the 1/1/1990 default date. Also if you can address the issue of a an erroneous date like 10/03/200 returning good on a straight CDate conversion.
Thank you for your help.
Ken
Hi, Ken.
Your code should look like the following: -
Public Function ConvertDate(varInput As Variant) As Date
-
-
On Error GoTo ConvertionFailed
-
ConvertDate = CDate(varInput)
-
Exit Function
-
ConvertionFailed:
-
ConvertDate = #1/1/1990#
-
-
End Function
-
P.S.
Or it may me even more simple (though maybe not so clear): -
Public Function ConvertDate(varInput As Variant) As Date
-
-
ConvertDate = #1/1/1990#
-
On Error Resume Next
-
ConvertDate = CDate(varInput)
-
-
End Function
-
Hi, Ken.
Your code should look like the following: -
Public Function ConvertDate(varInput As Variant) As Date
-
-
On Error GoTo ConvertionFailed
-
ConvertDate = CDate(varInput)
-
Exit Function
-
ConvertionFailed:
-
ConvertDate = #1/1/1990#
-
-
End Function
-
P.S.
Or it may me even more simple (though maybe not so clear): -
Public Function ConvertDate(varInput As Variant) As Date
-
-
ConvertDate = #1/1/1990#
-
On Error Resume Next
-
ConvertDate = CDate(varInput)
-
-
End Function
-
Hi FishVal, here is what I did.
Orig Data:
ID Field2 Field3
1 01/01/1990 00:00 AM
2 7/9/2003 10:15:30 PM
3 7 /9/2003 09:15 AM
4 5/5/192 01:25:15 PM
5 01/01/1990 08:15
6 01/01/1990 00:00 AM
7 8/5/07 00:00 AM
8 10/03/200 07:15
9 03/35/44 08:15
10 3/17/40 00:00 AM
Here is code in Module:
(CODE)
Public Function ConvertDate(varInput As Variant) As Date
Dim Field2 As String
On Error GoTo ConvertionFailed
ConvertDate = CDate(Field2)
Exit Function
ConvertionFailed:
ConvertDate = #1/1/1990#
End Function
(/CODE)
Results:
ID Field2 Field3 Expr1
1 01/01/1990 00:00 AM 1/1/1990
2 7/9/2003 10:15:30 PM 1/1/1990
3 7 /9/2003 09:15 AM 1/1/1990
4 5/5/192 01:25:15 PM 1/1/1990
5 01/01/1990 08:15 1/1/1990
6 01/01/1990 00:00 AM 1/1/1990
7 8/5/07 00:00 AM 1/1/1990
8 10/03/200 07:15 1/1/1990
9 03/35/44 08:15 1/1/1990
10 3/17/40 00:00 AM 1/1/1990
Sure, this will not work.
Look at the last variant of code I've posted.
Sure, this will not work.
Look at the last variant of code I've posted.
Hi Fish,
I am not sure where we are going here. If you mean the new type function you sent. I don't understand it at all.
Ken I thought the first one should have worked. It did , only just a little too well....
Hi Fish,
I am not sure where we are going here. If you mean the new type function you sent. I don't understand it at all.
Ken I thought the first one should have worked. It did , only just a little too well....
It worked.....yippee
Ken
I chgs the variable back to the variable....varinput...
as you had ...
Results..
ID Field2 Field3 Expr1
1 01/01/1990 00:00 AM 1/1/1990
2 7/9/2003 10:15:30 PM 7/9/2003
3 7 /9/2003 09:15 AM 7/9/2003
4 5/5/192 01:25:15 PM 5/5/192
5 01/01/1990 08:15 1/1/1990
6 01/01/1990 00:00 AM 1/1/1990
7 8/5/07 00:00 AM 8/5/2007
8 10/03/200 07:15 10/3/200
9 03/35/44 08:15 1/1/1990
10 3/17/40 00:00 AM 3/17/1940
This was mainly pointing at case nbr 9 and it worked great...thank you
now if I can get case 4 and 8 it will be over.
Ken
To begin with, checking the AfterUpdate status of a textbox control to see if it's Null is a wasted exercise! The AfterUpdate will only fire if a value has been manually entered into the textbox. If the box is entered but a value hasn't been entered, or if a value has been entered and then deleted, the value will always be Null, so checking for Null before proceeding further is, in this particular case, useless.
The standard way of checking to see if data is a date is to use the IsDate() function. What this function actually does is check to see if the data looks like a date! If so, it returns True. Both
IsDate( #12/26/2007#)
and
IsDate( "12/26/2007")
return True. IsDate() is useless, however, to test to see if 01/10/492 is a valid date, for the simple reason that 01/10/492 is a valid date! The year 492 did exist! Used with either IsDate() example given above, 01/10/492 will evaluate as True.
The only way I see to solve this problem is either to use an Input Mask or to check to see if 3 digits have been entered for the year. This code does that, and if 3 digits have been entered for the year, a default date is substituted. - Private Sub txtDate_AfterUpdate()
-
If Len(Me.txtDate) - InStrRev(Me.txtDate, "/") = 3 Then
-
Me.txtDate = #1/1/1990#
-
End If
-
End Sub
Linq ;0)> Post script:
The above also explains why the code used in the last post doesn't work in cases #4 and #8.
To begin with, checking the AfterUpdate status of a textbox control to see if it's Null is a wasted exercise! The AfterUpdate will only fire if a value has been manually entered into the textbox. If the box is entered but a value hasn't been entered, or if a value has been entered and then deleted, the value will always be Null, so checking for Null before proceeding further is, in this particular case, useless.
The standard way of checking to see if data is a date is to use the IsDate() function. What this function actually does is check to see if the data looks like a date! If so, it returns True. Both
IsDate(#12/26/2007#)
and
IsDate("12/26/2007")
return True. IsDate() is useless, however, to test to see if 01/10/492 is a valid date, for the simple reason that 01/10/492 is a valid date! The year 492 did exist! Used with either IsDate() example given above, 01/10/492 will evaluate as True.
The only way I see to solve this problem is either to use an Input Mask or to check to see if 3 digits have been entered for the year. This code does that, and if 3 digits have been entered for the year, a default date is substituted. - Private Sub txtDate_AfterUpdate()
-
If Len(Me.txtDate) - InStrRev(Me.txtDate, "/") = 3 Then
-
Me.txtDate = #1/1/1990#
-
End If
-
End Sub
Linq ;0)> Post script:
The above also explains why the code used in the last post doesn't work in cases #4 and #8.
Thank you very much for the insight. As I am still working on this I will try to understand and use what you have here. Thanks for taking the time. Ken
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Eddie |
last post by:
I need to validate a text input field.
I just want to say if user enters
93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109
or 93110 or 93111 or 93116 or 93117 or 93118 or...
|
by: Steven T. Hatton |
last post by:
Some people have suggested the desire for code completion and refined
edit-time error detection are an indication of incompetence on the part of
the programmer who wants such features. ...
|
by: FAQPoster |
last post by:
An HTML version of this document is available at:
http://www.mvps.org/access/netiquette.htm
Feeling left out? Alone? Wondering why everyone's ignoring you?
Or why you're being flamed for what...
|
by: James Edwards |
last post by:
There seems to be a bug in the link-library dependency checking in VS.NET 2003.
Under the Configuration->Linker->General->Additional Library Directories
property,
if you specify a directory name...
|
by: John Wildes |
last post by:
Hello all
I'm going to try and be brief with my question, please tell me if I have the
wrong group.
We are querying transaction data from a DB3 database application. The dates
are stored as...
|
by: franco |
last post by:
I am a beginner in programming. How can I display the system date - 5
December 2005 in my webpage.
|
by: jacob navia |
last post by:
We hear very often in this discussion group that
bounds checking, or safety tests are too expensive
to be used in C.
Several researchers of UCSD have published an interesting
paper about this...
|
by: Kyote |
last post by:
In my project I have an underlying Access DB. One of the column's is
currently set as a text field but I need to change it to a date/time
field.
I can open the Access DB in MS Access and change...
|
by: RobG |
last post by:
I was investigating a function to determine whether daylight saving
was being observed on a particular date (given the platform's regional
settings) and came across a suggestion at merlyn.com to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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,...
|
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...
| |