Validating user form textboxes
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 6 of 6

Thread: Validating user form textboxes

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I have a textbox on a userform in visual basics which will have the date manually typed into it. When the OK button is pressed the date is cut and pasted into a cell in Excel. Is there any way to validate the textbox to prevent an incorrect date being inserted? I have tried validating the cell that the date is pasted into but if an incorrect date is entered the debug box is displayed.

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,936
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have a textbox on a userform in visual basics which will have the date manually typed into it. When the OK button is pressed the date is cut and pasted into a cell in Excel. Is there any way to validate the textbox to prevent an incorrect date being inserted? I have tried validating the cell that the date is pasted into but if an incorrect date is entered the debug box is displayed.
    Hello,

    You could use some code like this to ensure that a date has been entered:-

    Code:
    Private Sub cmdOK_Click()
    If IsDate(Me.txtDate) = False Then
        MsgBox "A valid date must be entered", vbExclamation, "Invalid Entry"
        Me.txtDate.Text = ""
        Me.txtDate.SetFocus
        Exit Sub
    End If
    
    'Rest of your code will execute here if a valid date has been entered
    
    End Sub
    Hope it helps,

    D

  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default


  4. #4
    New Member
    Join Date
    Mar 2002
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    hi, Thanks for the code. I have inserted it into the userform. The only problem is that even if i enter a valid date the debug appears and the .Txtdate in 'If(Me.txtdate)' is highlighted in blue. A message box appears saying "Comppile Error: Method or data member not found". Do you have any suggestions as to how i can ammend this problem? Thanks in advance for any help you can provide me with.

  5. #5
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi

    Try this

    Private Sub CommandButton1_Click()
    If Not IsDate(TextBox1.Value) Then
    TextBox1.SetFocus
    MsgBox "A valid date must be entered", vbExclamation, "Invalid Entry"
    TextBox1 = vbNullString
    Else
    Sheet1.Range("A65536").End(xlUp).Offset(1, 0) = TextBox1.Value
    TextBox1 = vbNullString
    End If

    End Sub

  6. #6
    New Member
    Join Date
    Mar 2002
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Thanks alot for the suggestion. It works perfectly. I much appreciate your help.

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
  •  

 

 
DMCA.com