Well anyhow, You may have posed a good question. Reason why I mentioned
"May", it seems as though lots of Access Developers haven't really ran into
an issue too much about what happens when a mouse user clicks on a command
button and can't get it to work due to some validation code preventing the
command button to get the focus, but it's this very issue that I don't like
using the BeforeUpdate Event for validation purposes, which means my forms
can't be bound, if I'm going to have data validation. Why it's this very
issue, it's not 100% of the time you want that exact same method of data
validation check to take place whenever a user clicks on a command button.
Why use the KeyDown Event instead of the BeforeUpdate Event?
Well this is a 2 part answer:
Part 1:
The BeforeUpdate Event is ran every single time an update is about to take
place including when a user wants to click on a command button that doesn't
require the previous control to be validated in it's normal way (I.e. Either
clicking on a "Help" command button or a command button that reset's the
form.), so to get around this issue, I have created my own CausesValidation
Property similation and Validate Event.
Part 2:
It's best to catch errors as soon as possible, so from the stand point of
general format requirements, the KeyDown Event is the best place to catch
those types of issues while the Validate Event (that I have custom created
to get around the mouse user friendly issue within Access - See Part 1
above) catches the specific validation errors.
Results:
For this to work, I can not work with bound forms due to the very fact of
how the Events works in Access on bound forms, which makes it not mouse user
friendly (the sole reason why I don't use bound forms). It has thus far
proven to be working out, though some standardization is required, but for
the most part, there's not much to it that's really different, other than
for the fact that the error messages are designed to show up in a label on a
form rather than in a message box, and messages generally tends to be more
user friendly than what Access would have it by default.
This has been coded for 3 months now and I have for the last 3 months been
worked on Form Behavior issues. I have lately finished up the form behavior
issues and moved onto the specific forms, and even that's working out pretty
good up to this point of time.
As you may have guessed, I have a DB program planned out that I spent quite
a few hours (maybe a couple thousand, but not sure as I do other things too
other than just programming), of which I would eventually like to see this
go into a SQL Server Environment, but I don't have the say so in that.
During this time, I basically felt that I needed to see about developing
some basic things for the base foundation of my DB program and start testing
to see how things works out. Over the last 6 months, I have learned a lot
of in depth stuff with Access and DAO programming of which before I could
take it to SQL Server, I will have to get the DAO programming converted to
ADO programming. At this time though, my biggest focus is to get the main
part of my DB program completed (at least the first version of it) and
implemented. That may mean it will have to fore go some things for the time
being, but that doesn't mean it can't be planned for. However, with this
first version, I still require the strict data validation and for my
internal users to use the program, it has to be user friendly of which a lot
of them are more or less mouse users that only uses the keyboard for things
that can't be used with the mouse too easily.
--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
John Nurick said:
Ronald,
I hope you'll forgive me for suspecting that you may have got a bit too
close to the trees to see the wood. Is it really really necessary to do
data validation on the KeyDown event? I'm struggling to think of a
situation in which that would be necessary. Normally I'd do the
validation on BeforeUpdate, and only use the keyboard events (usually
KeyPress) to limit the characters that could be input.
For dates and times, I'm not sure what the point is in requiring the
user to adhere to a specific format when inputting data. CDate() and
similar functions can recognise a wide range of date strings; once
converted to an Access date/time value, textboxes and the Format()
function can display it in the locale-dependent formatting.
But if you actually do need to "read the keyboard" I suggest that you
search in the Visual Basic forums. It's much more likely that someone in
that world will have written the function you're looking for, and (as a
rule) VB functions using the Windows API need little or no modification
to work in VBA.
Well as I mentioned before, there are few cases where I would like to be
able to convert the KeyCode and the Shift code to ASCII character code
including the punctuations, and other keys that does have ASCII codes.
However, I also know that even depending on what either the numlock and/or
caps lock keystate is (where GetKeyState comes into play), it can also mean
the difference between the shifted character and the unshifted character.
Example, if Caps Lock is on, when someone pressed Shift-A, it actually
returns a lower case A (a). What if I wanted to return the ASCII code for
the colon
) for when someone pressed the Shift Key and the key that
correspond to the colon (KeyCode of 186 and Shift value of 1). Of course,
the Caps lock toggle key value would only affect the letters while the
numlock affects the numbers and decimal key on the numpad. Not only that, I
already have the values of all 4 toggle keys, and 3 modifier keys (20, 45,
144, 145 for caps, insert, numlock, and scroll lock while it's 16, 17, 18
for Shift, Ctrl, and Alt) from when I had setup my other general data
validation checks. Now, I have moved into the area of validating dates and
times just to be sure it even meets the format requirements based on locale
settings, so here's what I was thinking, if I take the KeyCode and the Shift
value, convert that to the ASCII code, which then gets converted to the
actual character, then compare that to the locale date/time separator (which
ever separator that it's being compared to) that is in the regional
settings, then I would just use the function that's already included, but
from what I get the feeling, there is no function (at least known to the
group) that has already been created and made available, thus would lead me
to believe I have to create my own function, but then in that case, it would
only be US locale version, thus has me actually thinking to go in another
direction, if this isn't already available.
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.