Results 1 to 5 of 5

Thread: Validating a control array

  1. #1

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Question 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?
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  2. #2
    New Member
    Join Date
    Oct 2001
    Posts
    6

    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

  3. #3

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    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.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  4. #4
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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:
    1. Dim curIndex As Integer
    2.  
    3. Private Sub Text1_Validate(Index As Integer, Cancel As Boolean)
    4.     curIndex = Me.ActiveControl.Index
    5. End Sub
    6.  
    7. Private Sub Text1_GotFocus(Index As Integer)
    8.     If Index < curIndex Then Debug.Print "now"
    9. End Sub
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  5. #5

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    Bum - that looks like it might be exactly what I'm after.

    Thanks...
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width