Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Capturing the first keystroke

Geek News

Capturing the first keystroke
Proko 12/14/2008 5:55:00 AM
What form event do I use to trap a users first keystroke on an unbound form?
I have placed breaks on KeyUp, KeyDown and KeyPress but none of the events
seem to trigger with a keystroke. If I could work this out I would then moove
on to the following problemwhich someone may be able to help me with also.
I have declared as public fFirstKeyStroke as Boolean, I'm not sure how to
set its initial value. I thought maybe Const fFirstKeyStroke = True, but I
get an error message when the form loads.
My plan is to log the first keystroke event in a temporary table to be saved
to a permanent audit table once the record is saved. Any help would be
greatly appreciated.
RE: Capturing the first keystroke
OssieMac 12/14/2008 7:44:00 AM
Hi Proko,

Not sure that this is the best or only answer but you could possibly use
something like the following on every control into which the user could enter
data.
NOTE that Dim firstKeyPressed As Boolean is in the declarations area at the
top of the form. That way it retains its value all the time the form is open
and its default value is False when the form opens. (I put the msgbox in for
testing only.)

Option Compare Database
Option Explicit
Dim firstKeyPressed As Boolean 'Default value is false

Private Sub Text0_KeyPress(KeyAscii As Integer)

If firstKeyPressed = False Then
firstKeyPressed = True
MsgBox "Key pressed is " & Chr(KeyAscii)
End If

End Sub

You could even consider disabling all controls but the one with the above
code and then enable the remaining controls after the first key stroke.

--
Regards,

OssieMac


"Proko" wrote:

[Quoted Text]
> What form event do I use to trap a users first keystroke on an unbound form?
> I have placed breaks on KeyUp, KeyDown and KeyPress but none of the events
> seem to trigger with a keystroke. If I could work this out I would then moove
> on to the following problemwhich someone may be able to help me with also.
> I have declared as public fFirstKeyStroke as Boolean, I'm not sure how to
> set its initial value. I thought maybe Const fFirstKeyStroke = True, but I
> get an error message when the form loads.
> My plan is to log the first keystroke event in a temporary table to be saved
> to a permanent audit table once the record is saved. Any help would be
> greatly appreciated.
Re: Capturing the first keystroke
"Stuart McCall" <smccall[ at ]myunrealbox.com> 12/14/2008 12:34:30 PM
"Proko" <Proko[ at ]discussions.microsoft.com> wrote in message
news:BF24E9B3-AE84-48C1-BEBA-C769046E6C0E[ at ]microsoft.com...
[Quoted Text]
> What form event do I use to trap a users first keystroke on an unbound
> form?
> I have placed breaks on KeyUp, KeyDown and KeyPress but none of the events
> seem to trigger with a keystroke. If I could work this out I would then
> moove
> on to the following problemwhich someone may be able to help me with also.
> I have declared as public fFirstKeyStroke as Boolean, I'm not sure how to
> set its initial value. I thought maybe Const fFirstKeyStroke = True, but I
> get an error message when the form loads.
> My plan is to log the first keystroke event in a temporary table to be
> saved
> to a permanent audit table once the record is saved. Any help would be
> greatly appreciated.

Set the form property "KeyPreview" to Yes/True and the events will then
work.


Re: Capturing the first keystroke
Proko 12/14/2008 9:40:10 PM
Thankyou. Both replies answer my question. Very much appreciated.

"Stuart McCall" wrote:

[Quoted Text]
> "Proko" <Proko[ at ]discussions.microsoft.com> wrote in message
> news:BF24E9B3-AE84-48C1-BEBA-C769046E6C0E[ at ]microsoft.com...
> > What form event do I use to trap a users first keystroke on an unbound
> > form?
> > I have placed breaks on KeyUp, KeyDown and KeyPress but none of the events
> > seem to trigger with a keystroke. If I could work this out I would then
> > moove
> > on to the following problemwhich someone may be able to help me with also.
> > I have declared as public fFirstKeyStroke as Boolean, I'm not sure how to
> > set its initial value. I thought maybe Const fFirstKeyStroke = True, but I
> > get an error message when the form loads.
> > My plan is to log the first keystroke event in a temporary table to be
> > saved
> > to a permanent audit table once the record is saved. Any help would be
> > greatly appreciated.
>
> Set the form property "KeyPreview" to Yes/True and the events will then
> work.
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net