[AccessD] Set Focus On Control When Validation Fails

John Clark John.Clark at niagaracounty.com
Mon Mar 10 12:39:00 CST 2003


I put the following in the "Before Update" event:

If datFromSheriff.Value < datToSheriff.Value Then
    MsgBox "The return date cannot be previous to the Sent to Sheriff
date", vbOKOnly, "Date Error"
    Cancel = True
    Me!datFromSheriff.Undo
    datFromSheriff = ""
    datFromSheriff.SetFocus
End If

And it now works fine. I actually got it after reading Andy's
suggestion about "Cancel." I meant to send an Email that I got it, but I
was called away from my desk for a couple of hours.

Thanks!

John W Clark

>>> bchacc at san.rr.com 03/10/03 11:31AM >>>
John:

Turns out my results were not as weird as my programming.  I had an
error in
the ValidationTests function.  I wasn't returning False from the
function on
the fields that failed to work correctly when their validation test
failed.
Fixed it and now the code below works correctly on all fields.  Yours
should
work as well. Does your BeforeUpdate event not work?  (You don't, I
think,
need the .SetFocus).

With much egg on face,

Rocky Smolin
Beach Access Software

----- Original Message -----
From: "Rocky Smolin - Beach Access Software" <bchacc at san.rr.com>
To: <accessd at databaseadvisors.com>
Sent: Monday, March 10, 2003 8:15 AM
Subject: Re: [AccessD] Set Focus On Control When Validation Fails


> John:
>
> My result is weirder than yours.  I have seven fields I put the
validation
> code into the BeforeUpdate event (no need for .SetFocus, because the
focus
> *in theory* never goes away from the control).
>
> I have a bunch of validation tests in a function:
>
> Private Sub txtBarCodePrefix_BeforeUpdate(Cancel As Integer)
>     If ValidationTests = False Then Cancel = True
> End Sub
>
> Works on three, fails on four.  And I can't see ANY differences
between
the
> three that work and the four that don't.  Could it be timing problem
in
the
> event sequence?  Maybe I'll try putting a delay loop in the
BeforeUpdate
> event, see if that changes anything.
>
> Rocky Smolin
> Beach Access Software
>
> ----- Original Message -----
> From: "John Clark" <John.Clark at niagaracounty.com>
> To: <accessd at databaseadvisors.com>
> Sent: Monday, March 10, 2003 7:19 AM
> Subject: Re: [AccessD] Set Focus On Control When Validation Fails
>
>
> > How weird...I am working on the exact same problem. I noticed that
a
> > program that I am about to roll out accepts any date, in the many
date
> > fields. Some of the dates need to be later than others that are
there
> > (for instance, there is a "Sent to Sheriff" field, and a "Returned
from
> > Sheriff" field, and you cannot receive it before it is sent).
> >
> > I used the code:
> >
> > If datFromSheriff.Value < datToSheriff.Value Then
> >     MsgBox "This date cannot be previous to the Sent to Sheriff
Date",
> > vbOKOnly, "Date Error"
> >     datFromSheriff = ""
> >     datFromSheriff.SetFocus
> > End If
> >
> > And I have tried it in the "On Lost Focus", "On Change" (stupid),
> > "Before Update" (there now), and "After Update" events, but none
worked.
> > It actually worked with "Lost Focus" but the SetFocus did not...it
went
> > to the next field in the tab order.
> >
> > Did you get this working?
> >
> > John Clark
> >
> >
> > >>> bchacc at san.rr.com 03/09/03 01:45PM >>>
> > 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
> > _______________________________________________
> > AccessD mailing list
> > AccessD at databaseadvisors.com 
> > http://databaseadvisors.com/mailman/listinfo/accessd 
> > Website: http://www.databaseadvisors.com 
>
>
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com 
> http://databaseadvisors.com/mailman/listinfo/accessd 
> Website: http://www.databaseadvisors.com 
>


_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com 
http://databaseadvisors.com/mailman/listinfo/accessd 
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list