473,480 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SetFocus problem when in "OnExit" event


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
4 10157
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
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

68
4281
by: Marco Bubke | last post by:
Hi I have read some mail on the dev mailing list about PEP 318 and find the new Syntax really ugly. def foo(x, y): pass I call this foo(1, 2), this isn't really intuitive to me! Also I...
0
2326
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
0
1993
by: Alex Nordhus | last post by:
I need some help. I cant seem to get rid of this error. I can program a button that will exit the program and remove the icon in the taskbar, but I have to tie it to OnTaskBarClose. OnExit and...
3
3396
by: arun venkatesan | last post by:
Hi, We use a TListView component in C++ Builder to enable the user make some selections. When the user makes a selection, the selected rows are highlighted in 'Blue'. Now, my application is...
0
1106
by: David Mitchell | last post by:
I have a form (frmAcq) which the user enters details of goods received including the total number of items received. The form has a subform (sfmAcqDetail) in which the user enters a breakdown of...
12
12887
by: swingingming | last post by:
Hi, in the NorthWind sample database, when clicking on the next navigation button on the new order record with nothing on the subform (order details), we got an order with nothing ordered. How can...
2
1770
by: T Conti | last post by:
Hello: I created a basic windows service that polls a db and sends emails to our subscribers. In the onstart method I create a new thread and send it on its way to do work. It should never end...
19
11455
by: ern | last post by:
Right now I'm using exit(0) to terminate my program. My program is a console .exe application. After the "exit(0)" line of code is encountered, the console application waits for an enter press,...
21
13388
by: brucedodds | last post by:
I have an Access 2003 form bound to a SQL Server table via ODBC. Often clicking a button on the form has the effect of requerying the form rather than firing the OnClick event. Does anyone have...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6886
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.