[AccessD] Set Focus On Control When Validation Fails

Andy Lacey andy at minstersystems.co.uk
Sun Mar 9 16:38:00 CST 2003


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/20030309/88b09053/attachment-0001.html>


More information about the AccessD mailing list