Rocky Smolin - Beach Access Software
bchacc at san.rr.com
Mon Mar 10 10:15:00 CST 2003
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