Strange behavior moving from Access 97 to Access 2000

J

John S. Ford, MD

I have a form with an embedded subform (in datasheet view) and if the user
is in the new record field and doesn't enter data into it, I want him to be
able to jump to the next field (which is on the MAIN form and is in the next
page of a tab control) by hitting <Tab> or <Return>.

I placed the following code in the OnKeyDown event for the control (which
happens to be a ComboBox) on the subform:

Private Sub cboDiagnosis_KeyDown(KeyCode As Integer, Shift As Integer)
Dim ShiftDown As Integer, CtrlDown As Integer, AltDown As Integer
ShiftDown = (Shift And acShiftMask) > 0
CtrlDown = (Shift And acCtrlMask) > 0
AltDown = (Shift And acAltMask) > 0
If Me.NewRecord = True And Not Me.Dirty And _
Not ShiftDown And Not CtrlDown And Not AltDown And _
(KeyCode = vbKeyReturn Or KeyCode = vbKeyTab) Then
Me.Parent!txtPatientAllergies.SetFocus
End If
End Sub

txtPatientallergies is the control I want the cursor to jump to. This code
works perfectly in Access 97 but when I run this database in Access 2000 the
code somehow SKIPS the txtPatientAllergies control and jumps into the
following control (which happens to be another subform control).

Any idea why this bug doesn't happen if I run the mdb file in Access 97 but
does in Access 2000?

John
 
D

Dirk Goldgar

John S. Ford said:
I have a form with an embedded subform (in datasheet view) and if the
user is in the new record field and doesn't enter data into it, I
want him to be able to jump to the next field (which is on the MAIN
form and is in the next page of a tab control) by hitting <Tab> or
<Return>.

I placed the following code in the OnKeyDown event for the control
(which happens to be a ComboBox) on the subform:

Private Sub cboDiagnosis_KeyDown(KeyCode As Integer, Shift As Integer)
Dim ShiftDown As Integer, CtrlDown As Integer, AltDown As Integer
ShiftDown = (Shift And acShiftMask) > 0
CtrlDown = (Shift And acCtrlMask) > 0
AltDown = (Shift And acAltMask) > 0
If Me.NewRecord = True And Not Me.Dirty And _
Not ShiftDown And Not CtrlDown And Not AltDown And _
(KeyCode = vbKeyReturn Or KeyCode = vbKeyTab) Then
Me.Parent!txtPatientAllergies.SetFocus
End If
End Sub

txtPatientallergies is the control I want the cursor to jump to.
This code works perfectly in Access 97 but when I run this database
in Access 2000 the code somehow SKIPS the txtPatientAllergies control
and jumps into the following control (which happens to be another
subform control).

Any idea why this bug doesn't happen if I run the mdb file in Access
97 but does in Access 2000?

Please don't post to so many groups. Formscoding is clearly the most
relevant group, while Gettingstarted is plainly irrelevant.

There does seem to be a change in behavior between Access 97 and 2000
here, though I haven't done the research to see if the change is
documented. What is happening in Access 2000 is that the keystroke you
are trapping in your Keydown event procedure is not being cancelled, so
it remains in the buffer and is subsequently processed by the
txtPatientAllergies control. Thus, that control has the focus, receives
the Tab or Enter key, and sends the focus on to the next control in the
tab order.

You can prevent this by deleting the key from the buffer before setting
the focus, like this:

KeyCode = 0
Me.Parent!txtPatientAllergies.SetFocus
 
J

John S. Ford, MD

Thank you Dirk. Your solution worked perfectly. I don't know why the
difference between Access 97 vs. 2000. Have you seen this problem occur in
other contexts ie. key strokes being stored in the mystical buffer? Is that
how you solved this problem so quickly?

PS: I'll try to keep the multiple posting down but according to the MS
Newsgroup "FAQ's", this type of multi-posting is considered fair
"netiquette".
 
D

Dirk Goldgar

John S. Ford said:
Thank you Dirk. Your solution worked perfectly. I don't know why the
difference between Access 97 vs. 2000. Have you seen this problem
occur in other contexts ie. key strokes being stored in the mystical
buffer? Is that how you solved this problem so quickly?

I've seen something like it before in the context of key-processing
events, when tab or enter keys are involved. The surprise to me was
that the original code worked in Access 97, as my experience had led me
to believe that it woud not.
PS: I'll try to keep the multiple posting down but according to the
MS Newsgroup "FAQ's", this type of multi-posting is considered fair
"netiquette".

What you did is actually cross-posting, not multi-posting.
Multi-posting is posting the same question independently, as a separate
article, to multiple groups, and it is inherently bad, no matter how
relevant the groups are, because it interferes with proper community
discussion and wastes people's time. Cross-posting, on the other hand,
is perfectly okay so long as the groups are all relevant to the
question. It should be used sparingly, though.

I really am not setting myself up as a newsgroup policeman, but the
newsgroups work best everyone when certain conventions are observed.
Since your question is about coding on forms, and there's a specific
newsgroup designated for that very topic, that newsgroup --
microsoft.public.access.formscoding -- is really the only newsgroup to
which the question should have been directed, at least on its first
posting. I can see including the m.p.a.forms group, because the
question also involved forms, but it really shouldn't be necessary. And
the question is certainly off-topic for microsoft.public.access, which
should only be used when no appropriate specialized group exists, and
for microsoft.public.access.gettingstarted.

I'm not sure what MS Newsgroup FAQ you're looking at, but I doubt it
approves cross-posting to irrelevant newsgroups. Here's another
Netiquette FAQ to look at:

http://www.mvps.org/access/netiquette.htm

Anyhow, none of this is such a big deal, really. I just wanted to let
you know that you were cross-posting too widely.
 
J

John S. Ford, MD

Fair enough! No more posting in the .gettingstarted or .access groups. It
seems to me that .forms and .formscoding were both fair though. I meant
CROSS posting by the way. I've never really MULTI-posted.

At any rate, thank you VERY much for the help!

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top