Dan Waters
dwaters at usinternet.com
Mon Mar 10 10:03:00 CST 2003
BeforeUpdate is a great method to prevent changes if a validation check
requires that.
The code below simply puts the focus where I want it, regardless of
where it was to begin with. It can be used within a validation check,
or anyplace you might find it useful.
-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com] On Behalf Of Andy Lacey
Sent: Sunday, March 09, 2003 4:28 PM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Set Focus On Control When Validation Fails
But if you cancel a BeforeUpdate you then don't need to set focus cos it
never loses it.
Andy Lacey
http://www.minstersystems.co.uk <http://www.minstersystems.co.uk/>
-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com] On Behalf Of Dan Waters
Sent: 09 March 2003 21:22
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Set Focus On Control When Validation Fails
Rocky - If the focus is already on the control you are trying to set the
focus to, setting the focus in code doesn't work. Try this:
Replace
txtStartingRoomNumber.SetFocus
With
'-- Does txtStartingRoomNumber already have the focus?
If Screen.ActiveControl.Name <> txtStartingRoomNumber.Name Then
txtStartingRoomNumber.SetFocus
End If
Note: Intellisense may try to change ActiveControl.Name to
ActiveControl.Application - hold your ground and retype
ActiveControl.Name over ActiveControl.Application. You need to
determine the name of the control that has the focus.
If you are on a subform or your form has a subform and this doesn't work
there is a different solution.
HTH,
Dan Waters
-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com] On Behalf Of Rocky Smolin -
Beach Access Software
Sent: Sunday, March 09, 2003 12:45 PM
To: AccessD at databaseadvisors.com
Subject: [AccessD] Set Focus On Control When Validation Fails
Dear List
I have a couple of simple validation tests:
If Not IsNumeric(Nz(txtStartingRoomNumber)) Then
MsgBox "Starting Room Number Must Be Numeric.", vbExclamation
txtStartingRoomNumber.SetFocus
Exit Sub
End If
If Val(Nz(txtStartingRoomNumber)) > 9999999 Then
MsgBox "Starting Room Number Must Be Less Than 7 Digits.",
vbExclamation
txtStartingRoomNumber.SetFocus
Exit Sub
End If
in the AfterUpdate event of txtStartingRoomNumber. But the SetFocus
does not work. The focus ends up being set on the next control in the
tab sequence. I tried the tests in the Lost Focus event with the same
result.
I know there must be a simple way to return the focus to the control but
I can't see it. (Maybe I shouldn't work on Sunday but the kids are in
Sunday school and it's quiet.) :)
MTIA,
Rocky Smolin
Beach Access Software
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030310/3d436160/attachment-0001.html>