Results 1 to 12 of 12

How to use validation in right way in TextBox in side UserForm?

Threaded View

  1. #1
    Registered User
    Join Date
    06-27-2012
    Location
    Estonia
    MS-Off Ver
    Excel 2007
    Posts
    49

    How to use validation in right way in TextBox in side UserForm?

    Hi all

    Hope You Can you help me?
    Inside the userform I need to create textbox=TB that have validation so the TB.value is a date formated "dd.MM.yyyy HH:mm" example("17.02.2014 17:05")
    the TB.value will be add to the specific cells example (A1) then it is a date with same format! And if the another cell = A1 Format general, then that cell value shod be (Example 46215,13151)

    If the user will make mistake with format or with nr values, then he cant exit from TB ( Cancel=True! ) or it will corrected automatically!

    Code i used, but it will not give a positive result!
    If the user make mistake even by putting two space between time and date then it will not find error!

    Private Sub Alg_enter()
       
            Alg.Value = Now
            Alg.Text = VBA.Format(Now, "dd.MM.yyyy HH:mm")
            
            
          
       End Sub
       
    Private Sub Alg_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        Dim Alg As Date
        Dim aeg As Double
        'aeg = Me.Alg.Value
        'Me.Alg.Value = aeg
        Me.Alg.Value = VBA.Format(Me.Alg.Value(), "dd.MM.yyyy HH:mm")
    
    End Sub
    
    Sub Check_Lop_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        
        If Check_Lop.Value = True Then
            Lop.Enabled = True
        Else
            Lop.Enabled = False
        End If
        
    End Sub
     Private Sub Lop_Enter()
       'Lop.Value = Now
       
       'Lop.Value = Format(Now(), "dd.mm.yyyy hh:mm")
        Lop.Value = Now
        Lop.Text = VBA.Format(Now, "dd.MM.yyyy  HH:mm")
        
        
    End Sub
    
    Sub Lop_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        
    If Check_Lop.Value = True Then
        'MsgBox "Aeg puudu!", vbCritical
        'Dim küsim, küsim2
        'küsim = MsgBox("Kas tahad aega uuesti sisestada?", vbYesNo)
        '    If küsim = 6 Then
        '        Cancel = True
        '    End If
        Lop.Text = VBA.Format(Lop.Text(), "dd.MM.yyyy  HH:mm")
    
        Dim küsim2 As Byte
        If Lop.Value < Alg.Value Then
        '
            MsgBox "Kontrolli aega! Algus: " & Alg.Value & "Lõpp: " & Lop.Value
            küsim2 = MsgBox("Kas Tahad parandada?", vbYesNo, "Edasise tegevuse kinnitus!")
            
                If küsim2 = 6 Then
                    Cancel = True
                Else
                End If
        
        
        End If
    ElseIf Check_Lop.Value = False Then
        Lop.Value = ""
    
    End If
    
    End Sub
    Last edited by Reemet; 02-21-2014 at 04:03 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Data Validation in textbox on userform
    By nav505 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2013, 08:02 PM
  2. Data Validation in textbox on userform
    By nav505 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2013, 07:37 PM
  3. UserForm TextBox validation and focus
    By Indiana Epilepsy and Child Neurology in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-14-2011, 03:10 AM
  4. Userform Textbox updating a another userform textbox (im stuck!!)
    By wapwap in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-31-2011, 02:56 PM
  5. Data validation in TextBox on UserForm
    By tim_chisman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2010, 09:33 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1