Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: I've Made A User Form And I Need Help With Validation

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi, everyone I've got yet another problem with my data form that I've made In VBA, I Want A Text Box Which Data Is Entered To Only Allow The Following values "20" and "40" And If Any Other Is Entered A Error Message Coming Up Saying "You Can Only Enter 20 And 40!" Here the Code I Currently Have And Would Appreciate Some Help Thank You!


    Private Sub txtContainerType_Change()
    Sheet1.Range("B19").Value = txtContainerType
    End Sub

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    someone must know

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Why not use a combobox containing only 20 and 40?

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Further to this, in order to properly validate it so they cant type anything different into it, in the combobox's properties window set the following:

    Match Required - TRUE
    Style - 2fmStyleDropDownList

    Now they'll only be able to select exactly what's in your list, plus if they enter 2, it'll automatically complete the entry to 20 and the same for 40

  5. #5
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Ok I Need A Bit More Help Could You Give THe Whole Code Where I Would Put That In Please?

  6. #6
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    OK, draw yourself a Combobox in your form. Now double click on the form itself, NOT one of the objects in it. Now change:

    Private Sub UserForm_Click()
    to
    Private Sub Userform_Initialize()

    Underneath that put in these two lines of code:

    Combobox1.AddItem "20"
    Combobox1.AddItem "40"

    Now go back to the Userform and click once on the Combobox. In the properties window go down until you find Match Required and change it to TRUE, now find STYLE and change that to 2fmDropDownList

    Now try that out and it should work fine. They dont even have to click on the arrow if they down want to. Simply type 2 or 4 and it'll auto-complete

    Hope this helps

  7. #7
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi! it sort of helps however My combo box isn't under the click button here is all my code for the thing I hope this helps you more to help me sorry I suck @ VB

    Private Sub cmdEnterInvoiceData_Click()

    On Error GoTo WrongInput
    Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
    Exit Sub

    WrongInput:
    MsgBox "Please enter a number"
    txtInvoiceNum.Text = ""
    txtInvoiceNum.SetFocus

    End Sub



    Private Sub txtContainerType_Change()
    Sheet1.Range("B19").Value = txtContainerType
    Combobox1.AddItem "20"
    Combobox1.AddItem "40"

    End Sub

    Private Sub txtEnterREF_Change()
    Sheet1.Range("E11").Value = txtEnterREF
    End Sub

    Private Sub txtTo_Change()
    Sheet1.Range("B15").Value = txtTo
    End Sub

    Private Sub txtVessel_Change()
    Sheet1.Range("B16").Value = txtVessel
    End Sub

    Private Sub UserForm_Click()

    End Sub

  8. #8
    Board Regular
    Join Date
    Mar 2002
    Location
    Little Italy
    Posts
    93
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Beautiful Soundman, just beautiful! You solved a problem of mine with that Private Sub Userform_Initialize() thing, without knowing it. Care to take a glimpse at my SendKey prob while you're at it? Itīs down the line here somewhere...

  9. #9
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Tell you what Morrisey, I'll email you a sample I just did. If it's no good, then send me your form (if you can) back via email, and I'll take a look

  10. #10
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Audio My Real E-mail Is Arash_M_Salimi@Hotmail.Com

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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