|
-
Oct 1st, 2001, 10:41 AM
#1
Thread Starter
Fanatic Member
Validating a control array
I have a control array where people can enter data. This data needs to be validated against a database.
What I want to happen is if someone tries to tab forwards through the control array, their entry will be validated. However, if they tab backwards, it should not be validated.
An example might help, here. Say I have three controls in my array: Surname, FirstName and PhoneNo (in that order). If someone types in "Smith" and then tabs onto the FirstName field, their entry should be tested to see whether it exists on the DB. If it does, they are allowed to continue; if it doesn't they are alerted and Surname keeps the focus.
Once they have given a valid surname, they then want to fill in a FirstName. If they type in "John" and tab forward to the PhoneNo field, "John" should be validated against the Smiths in the DB. However, if they suddenly realise that they should have been looking for "Jones" and try to tab back to the Surname field, they don't want to keep being advised that they have entered an invalid FirstName (or have entered nothing at all).
Is there anyway that I can test where the focus is going before deciding whether to validate the entry?
-
Oct 1st, 2001, 10:45 AM
#2
New Member
Enter Key
Well if you use the TAB key to validate, its going to validate everytime that the textbox gets focus. The way I get around that is by using the keydown code. Such as Enter :
text1(keydown) event
if keycode = 13 then 'Enter pressed
Validate Text Box
text2.setfocus
endif
If Enter is hit, it validates
if tab is changed it doesn't
JDuke
-
Oct 1st, 2001, 10:48 AM
#3
Thread Starter
Fanatic Member
I'm not actually testing according to the key that is pressed; I'm using the validate event on the text box. I just need to be able to test where the focus has moved to.
Mind you - I could borrow part of your suggestion and test whether they used the Backtab key. That would solve part of it.
Thanks.
-
Oct 1st, 2001, 06:46 PM
#4
PowerPoster
Hi
This may be one idea although u would have to check for tabbing from the last entry to the first entry in the control array eg u could clear the variable when u tab from the last control array item to the entry button etc
Regards
Stuart
VB Code:
Dim curIndex As Integer
Private Sub Text1_Validate(Index As Integer, Cancel As Boolean)
curIndex = Me.ActiveControl.Index
End Sub
Private Sub Text1_GotFocus(Index As Integer)
If Index < curIndex Then Debug.Print "now"
End Sub
-
Oct 3rd, 2001, 04:06 AM
#5
Thread Starter
Fanatic Member
Bum - that looks like it might be exactly what I'm after.
Thanks...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|