Results 1 to 12 of 12

Thread: A Couple Quick Easy Questions..I Hope!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Lisle, IL USA
    Posts
    20

    Post

    Hi,

    First, I have an area where the user is to enter a phone number. There are three text boxes, one for each part of the number. When the user enters the 3 digit area code, I want the cusor to automatically move to the next box. I also have to make sure that when the data loads from the database it doesn't give an error like it is now.

    The other problem I am haveing is checking or restricting the user input. Specifically I have a Gender field were there are only suppose to enter M or F. How do I make sure that what they do?

    Thanks for any help you guys can give.

    Kevin

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    First question:
    Try this:
    Code:
    Private Sub Text1_Change()
        If Len(Text1.Text) = 3 Then
            Text2.SetFocus
        End If
    End Sub
    Last question:
    Maybe this will help:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If UCase(Chr(KeyAscii)) <> "M" And UCase(Chr(KeyAscii)) <> "F" Then
            KeyAscii = 0
        End If
    End Sub
    End Sub


    [This message has been edited by QWERTY (edited 11-14-1999).]

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Lisle, IL USA
    Posts
    20

    Post

    Thanks QWERTY,

    For the first one, I tried that and I got an error when the program loaded, here is the error:

    Run-Time Error '5':

    Invalid procedure call or argument

    The second, I can't enter anything. I think it might be the control so I am deleting it and recreating it. But, my PC crashed so I haven't been able to check it yet.

    Oh, if it helps any I am retrieving the data from an Oracle 8 DB.

    Thanks again!

    Kevin

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    QWERTY had the right idea, but his/her code is not correct. Not logic is always confusing, so try this:
    Code:
        If KeyAscii = vbKeyBack Then
            'Backspace
            Exit Sub
        End If
    
        If UCase(Chr(KeyAscii)) = "M" Or UCase(Chr(KeyAscii)) = "F" Then
        ' Valid
        Else
            KeyAscii = 0
            Beep
        End If
    ------------------
    Marty

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Lisle, IL USA
    Posts
    20

    Post

    Thanks Martin,

    I was able to get that part working fine. The problem was that I cannot set a MaxLenght for that field, any idea why? I want the user to only be able to enter one character.

    Also do you have any thoughts on the error I am getting for my first question.

    Thanks Again!

    Kevin

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    For your second question:

    Since you have only 2 choices (M or W), why don't you use a ComboBox or OptionButton where the user can select either M or W. This way you make the user always select the one without making a mistake.

    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Lisle, IL USA
    Posts
    20

    Post

    Thanks Guys,

    I am smacking myself in the head for not remembering about the Masked Edit box. But, I have one quick and hopefully final question.

    I get an error when I try to bind the Edit box to my database. I am using an actual ADO data object to connect to an Oracle DB and I can see the database field when I click on the Data Field property. But when the program loads it gives and error saying it cannot bind to the DB field.

    Any ideas?

    Thanks,

    Kevin

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    As far as restricting the user to 1 character, have you tried Text1.MaxLength = 1 in your form's load event or someplace?

    ------------------
    Marty

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Lisle, IL USA
    Posts
    20

    Post

    Martin,

    Yep, I tried it with the textbox and the code you gave me. But, I was unable to enter any characters period, even M or F. So I went ahead and created Option Buttons for them.

    Thanks for the help though.

    Kevin

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I was surprised to hear that my coder sample didn't work for you since I always test stuff before I post it, so I've emailed you a tiny project for future reference that does what I think you wanted to do, even though option buttons are the better choice.

    ------------------
    Marty

  11. #11
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    For ther first part of your question, you can use a Masked Edit Box for all three parts of your number. Set its mask property to something like this:

    (###)-###-####

    The cushions (numeral sign) means any digit, and the other characters will remain unchanged. You cursor will skip any character different than a digit. Guaranteed!

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Lisle, IL USA
    Posts
    20

    Post

    Martin,

    Thanks for sending me the sample project it was a help. I think it might have been cause I was setting the MaxLength at design time, or my program is just flakey and is possesed by a ghost. Thanks again, to everyone, for all the help, you saved my bacon.

    Kevin

    P.S. I am still kind of curious why the Masked Edit won't bind to my DB, anyone have any thoughts?

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