Controlling Cursor

F

Frank Wagner

I am having trouble controlling my cursor movement. I
have the following code in the On-Exit event for the SA2
text box.

If Me.SA2 <> Me.A1_2 Then
MsgBox ("The Correct Answer is " & Me.A1_2")
Me.SA2.SetFocus
End If

I want the cursor to return to the same text control if
the answer is wrong - but rather than return to the SA2
control it goes to the next text control in the Tab Order.

I am using Access 2000

Any help would be appreciated.

Frank Wagner
 
D

Dirk Goldgar

Frank Wagner said:
I am having trouble controlling my cursor movement. I
have the following code in the On-Exit event for the SA2
text box.

If Me.SA2 <> Me.A1_2 Then
MsgBox ("The Correct Answer is " & Me.A1_2")
Me.SA2.SetFocus
End If

I want the cursor to return to the same text control if
the answer is wrong - but rather than return to the SA2
control it goes to the next text control in the Tab Order.

I am using Access 2000

You can cancel the Exit event by setting the event procedure's Cancel
argument to True. That will keep the focus in the text box. However,
the BeforeUpdate event may be better for this purpose. It, too, has a
Cancel argument, which you would set to reject the user's input. The
main practical difference is that the Exit event will fire even if the
user is just tabbing through the control, while the BeforeUpdate event
will fire only if the user actually changes the value of the control.
 
G

Guest

Dirk:

I've never changed an event's properties on the fly. Can
I get part way through the Private Sub which responds to
the event, and then cancel the event itself. This will
allow me to notify the user that their answer is
incorrect, and then cancel the event leaving the cursor
where it started.

What would be an example of the code which I would make
part of the event?

Is there anything in my code which causes the SetFocus
argument not to work?

Thanks

Frank Wagner
 
D

Dirk Goldgar

Dirk:

I've never changed an event's properties on the fly. Can
I get part way through the Private Sub which responds to
the event, and then cancel the event itself. This will
allow me to notify the user that their answer is
incorrect, and then cancel the event leaving the cursor
where it started.

Yes, this is what I'm suggesting you do.
What would be an example of the code which I would make
part of the event?

I would use the BeforeUpdate event, not the Exit event, and would write
code like this:

'----- start of suggested code -----
Private Sub SA2 _BeforeUpdate(Cancel As Integer)

If Me.SA2 <> Me.A1_2 Then
MsgBox "The Correct Answer is " & Me.A1_2
Cancel = True
End If

End Sub
'----- end of suggested code -----

If you insist on using the Exit event instead, the code would be the
same except for the Sub header itself.
Is there anything in my code which causes the SetFocus
argument not to work?

SetFocus doesn't work where you used it because the focus hasn't
actually left the SA2 control when its Exit event fires. So setting the
focus to that control in the Exit event changes nothing -- the change of
focus that was pending, and triggered the Exit event, is still waiting
to be carried out, and will occur unless you cancel the event.
 

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