By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,863 Members | 879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,863 IT Pros & Developers. It's quick & easy.

SetFocus problem when in "OnExit" event

P: n/a

I am a newbie using Access 2000.

I am using the following test in the txtAlbum OnExit procedure to prevent
leaving an empty text box for a required field

If (IsNull(txtAlbum.Value)) Or (Len(txtAlbum.Value) < 1) Then
MsgBox("Album Title cannot be empty")
txtAlbum.SetFocus
End If

When the Message Box closes, the focus is on the control clicked on or is on
the next Tab Stop (depending on how I exit the text box.) Why doesn't the
SetFocus method work in this instance? I have event procedures for other
controls (Command Buttons) on my form which include

txtAlbum.SetFocus

that work fine.

Can anyone help me figure out what I am doing wrong? I suspect that the user
action (clicking outside the text box or pressing the Tab key) which initiates
the text box control's On Exit event has it's own Set Focus method that
executes after my statement. In any event I don't know what, if anything, to do
to change this behavior.

Paul Core

Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Paul,

After the MsgBox statement and before the set focus statement add:
Cancel = True

Stewart
"Corepaul" <co******@aol.combvwertz> wrote in message
news:20***************************@mb-m15.aol.com...

I am a newbie using Access 2000.

I am using the following test in the txtAlbum OnExit procedure to prevent
leaving an empty text box for a required field

If (IsNull(txtAlbum.Value)) Or (Len(txtAlbum.Value) < 1) Then
MsgBox("Album Title cannot be empty")
txtAlbum.SetFocus
End If

When the Message Box closes, the focus is on the control clicked on or is on the next Tab Stop (depending on how I exit the text box.) Why doesn't the
SetFocus method work in this instance? I have event procedures for other
controls (Command Buttons) on my form which include

txtAlbum.SetFocus

that work fine.

Can anyone help me figure out what I am doing wrong? I suspect that the user action (clicking outside the text box or pressing the Tab key) which initiates the text box control's On Exit event has it's own Set Focus method that
executes after my statement. In any event I don't know what, if anything, to do to change this behavior.

Paul Core

Nov 12 '05 #2

P: n/a
Thanks Stewart, it now works.

I went to the Access help files but am still a little unclear HOW it works.

According to the help file, the Cancel Method applies to three types of
objects, Connection, QueryDef, or Recordset. Can anyone help me understand what
object does this command acts on?

Paul Core
Nov 12 '05 #3

P: n/a
Have a look at the CancelEvent Action in the help file. This lists all the
events that can be canceled.

Stewart

"Corepaul" <co******@aol.combvwertz> wrote in message
news:20***************************@mb-m15.aol.com...
Thanks Stewart, it now works.

I went to the Access help files but am still a little unclear HOW it works.
According to the help file, the Cancel Method applies to three types of
objects, Connection, QueryDef, or Recordset. Can anyone help me understand what object does this command acts on?

Paul Core

Nov 12 '05 #4

P: n/a
> I went to the Access help files but am still a little unclear HOW it works.

According to the help file, the Cancel Method applies to three types of
objects, Connection, QueryDef, or Recordset. Can anyone help me understand what object does this command acts on?


It is an argument of the event procedure. Some event procedures
(Access-generated procedures) contain a "Cancel" argument, the default value of
which is "False". If you set this value to "True" within the procedure, the
event is cancelled. You can find this in Access Help - search for "event
property" in the "Index" tab of Help, select from the topic list "Events and
Event Properties Reference", then click on the "Exit" event in the pane to the
right, and then, in the resulting page, click on the "Event Procedures"
hyperlink at the top and, since there should only be one item in the dialog
list, simply click on "Display". I know it's a long and confusing haul to get
there, but there are a few weaknesses in Help in later versions.

--
Bruce M. Thompson, Microsoft Access MVP
bt******@mvps.org (See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.<<
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.