After entering a date (earlier than today's date) into a textbox
control though, I'm stumped as to why VBA thinks date I enter into the
control is greater than Now - when they are CLEARLY less than Now.
Here's the code I have in the AfterUpdate event. I must be overlooking
the obvious. Ideas?
Private Sub DateSigned_Afte rUpdate()
If Me!DateSigned Now Then
Me!DateSigned = Null
MsgBox "No Way Jose!"
End If
End Sub
Aug 3 '07
14 3500
<snip>
> The obvious: Check your SystemDate first .... What value does Now() give you ??
Please.
> BTW: If you are validating input, better use the BeforeUpdate event.
Point well taken. But if invalid input is discovered during the Before
Update event, one cannot take action to correct it. A very good
correction is to throw away the user input by setting the control to
Null. That WORKS in the AfterUpdate event but NOT in the Before
Update event...
Private Sub DateSigned_Afte rUpdate()
If Me!DateSigned Now Then
Me!DateSigned = Null
DoCmd.CancelEve nt
MsgBox "No Way Jose!"
End If
End Sub
The above will give you errors. There is NO WAY to take away the value
entered, leaving nothing in the control - during BeforeUpdate event
processing. AfterUpdate code is the ONLY logical place. Maybe I'm
wrong, but I cannot recall ever having seen any code posted that could
dynamically modify the contents of a textbox during BeforeUpdate event
code processing.
> Arno R
On Aug 8, 9:04 am, MLH <C...@NorthStat e.netwrote:
Seems that Tom van Stiphout hit it on the nose. Must-a-been
some kind-a-string comparison going on, rather than a date-to-date
comparison. I ran his suggested tests in the immediate window.
So I took banem2 up on his suggestion to encapsulate the textbox
reference inside CDate(). Apparently, that had an effect and seems
like the one I want.
Your comments re: Before vs After Update were well received too.
Thx.
After having made the 'fix', I found more places in my code were
greater-than / lesser-than comparisons may be returning questionable
results. So I'll likely take Tom van Stiphout up on his suggestion to
use DateDiff in some of these places. Although, I haven't tested and
am unsure what DateDiff(Forms! MyForm!MyContro l,Now) will do if user
types 8/15/2007 in a textbox without surrounding it with #...#
I guess, in the OP, I was hoping someone might know how I could
inform A97 that a particular textbox on a form contained a date and
that any subsequent use of the value in there would be treated as if
it were a date. I mean, I can use datediff, yeah. But, looking at an
integer difference representing the number of days between two dates
and considering the sign of the value returned is more trouble than
asking "Hey, is Date1 Date2?" Huh? Huh? That's quick & easy
whereas the former is labor-laden.
All data are strings. You can trust Access/VBA/JET to treat these
strings in the way you want them treated or you can declare and cast
everything yourself the way you would be required to do in many
programming languages. I choose the latter. If you have an unbound
text box how could Access "know" the string value in it should be
treated as date?
It's not very labor intensive to use the
CBool(expressio n)
CByte(expressio n)
CCur(expression )
CDate(expressio n)
CDbl(expression )
CDec(expression )
CInt(expression )
CLng(expression )
CSng(expression )
CStr(expression )
CVar(expression )
functions. And one might actually learn a little in the process.
Oh yeah, did I mention that his/her programs might work too.
MLH wrote:
<snip>
>> The obvious: Check your SystemDate first .... What value does Now() give you ?? Please.
BTW: If you are validating input, better use the BeforeUpdate event.
Point well taken. But if invalid input is discovered during the Before
Update event, one cannot take action to correct it. A very good
correction is to throw away the user input by setting the control to
Null. That WORKS in the AfterUpdate event but NOT in the Before
If you cancel the update and then issue an Undo on the control it will be
cleared, BUT if you use the Cancel = True in the BeforeUpdate it is better
to allow the user to correct the value (he will be forced to after all).
That way he can still see his invalid entry to determine what the problem
is.
For example if he accidentally enters the wrong year and you give him a
message like "Invalid Date" and then blank it out, sooner or later you will
have a user telling you that "Sometimes it tells me my entry is incorrect
when it is NOT incorrect". This of course would mean that he entered an
incorrect value but was not aware of it. By leaving the incorrect value in
the control you allow the user to examine it so he can slap his forehead and
say "Doh! That should be 2007, not 2006".
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
MLH wrote:
>Seems that Tom van Stiphout hit it on the nose. Must-a-been some kind-a-string comparison going on, rather than a date-to-date comparison. I ran his suggested tests in the immediate window. So I took banem2 up on his suggestion to encapsulate the textbox reference inside CDate(). Apparently, that had an effect and seems like the one I want.
Your comments re: Before vs After Update were well received too. Thx.
After having made the 'fix', I found more places in my code were greater-than / lesser-than comparisons may be returning questionable results. So I'll likely take Tom van Stiphout up on his suggestion to use DateDiff in some of these places. Although, I haven't tested and am unsure what DateDiff(Forms! MyForm!MyContro l,Now) will do if user types 8/15/2007 in a textbox without surrounding it with #...#
I guess, in the OP, I was hoping someone might know how I could inform A97 that a particular textbox on a form contained a date and that any subsequent use of the value in there would be treated as if it were a date. I mean, I can use datediff, yeah. But, looking at an integer difference representing the number of days between two dates and considering the sign of the value returned is more trouble than asking "Hey, is Date1 Date2?" Huh? Huh? That's quick & easy whereas the former is labor-laden.
As others have said, when you enter something like 8/15/2007
into a text box, Access has to try to figure out what it
should do with the characters. The first clue Access uses
in its guessing process is to check the type of the field
bound to the text box. If it's a Date type, you might be
ok. If it's a Text field, then you will probably see your
problem.
OTOH, if the text box is not bound, then Access looks at the
text box's Format property to see if it provides any clues.
If the Format is the kind used for a date/time, then you are
probably ok. Any other kind of format, including none will
lead Access off in the wrong direction and your data might
be interpreted in some way that you don't like.
If you follow Lyle's advice, you can avoid the "might" and
"probably" involved when you let Access play its guessing
game.
--
Marsh
Thx for the explanation, Marshall.
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxx
On Wed, 08 Aug 2007 13:29:12 -0500, Marshall Barton
<ma*********@wo wway.comwrote:
>MLH wrote:
>>Seems that Tom van Stiphout hit it on the nose. Must-a-been some kind-a-string comparison going on, rather than a date-to-date comparison. I ran his suggested tests in the immediate window. So I took banem2 up on his suggestion to encapsulate the textbox reference inside CDate(). Apparently, that had an effect and seems like the one I want.
Your comments re: Before vs After Update were well received too. Thx.
After having made the 'fix', I found more places in my code were greater-than / lesser-than comparisons may be returning questionable results. So I'll likely take Tom van Stiphout up on his suggestion to use DateDiff in some of these places. Although, I haven't tested and am unsure what DateDiff(Forms! MyForm!MyContro l,Now) will do if user types 8/15/2007 in a textbox without surrounding it with #...#
I guess, in the OP, I was hoping someone might know how I could inform A97 that a particular textbox on a form contained a date and that any subsequent use of the value in there would be treated as if it were a date. I mean, I can use datediff, yeah. But, looking at an integer difference representing the number of days between two dates and considering the sign of the value returned is more trouble than asking "Hey, is Date1 Date2?" Huh? Huh? That's quick & easy whereas the former is labor-laden.
As others have said, when you enter something like 8/15/2007 into a text box, Access has to try to figure out what it should do with the characters. The first clue Access uses in its guessing process is to check the type of the field bound to the text box. If it's a Date type, you might be ok. If it's a Text field, then you will probably see your problem.
OTOH, if the text box is not bound, then Access looks at the text box's Format property to see if it provides any clues. If the Format is the kind used for a date/time, then you are probably ok. Any other kind of format, including none will lead Access off in the wrong direction and your data might be interpreted in some way that you don't like.
If you follow Lyle's advice, you can avoid the "might" and "probably" involved when you let Access play its guessing game.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MMFBprez |
last post by:
I am trying to compute storage charges by getting the number of months
between dates and multiplying it by a rate. I cannot get a correct
number of months if the date is greater than a year ago. Here is the
formula I am using now to get the number of months: #ofMonths:
Month(.-.)-1.
It has worked for me until now because it never was greater than a
year before. Please help. I am a novice at this.
|
by: Lea |
last post by:
Having a problem with a query within a table for appointment schedules.
In this table tblMeetingInfo are two fields, StartDate and EndDate.
The date information is entered into each of these fields like:
1/12/2005 (This could represent data entered into either field).
Most appointments are one day in duration. In this example, StartDate
would be equal to Enddate: 1/12/2005 to 1/12/2005 (StartDate to
EndDate).
|
by: labelle |
last post by:
I have an event listing on my website that is pulling from SQL.
Unfortunately, the listing is displaying all events, especially those
that are even 2 years old. I want to get rid of them and only display
events that are today or in the future. I need help!
Dim tmpEvents As Events
tmpEvents = New EventsMapper().GetEvents()
Dim tmpEvent As New
Dim tmpEventListing As String
For Each tmpEvent In tmpEvents
|
by: jdph40 |
last post by:
I enter data into a database that resides on our network. Other
employees can print reports from the database, but they have no way of
telling if I've entered all the data. For instance, on Mondays, I
have to enter 3 days of data - Friday, Saturday, and Sunday. Last
Monday, an employee came to me questioning the results on his
report. He had requested data from the weekend: Friday through
Sunday. But when he printed the report, I had...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |