How to validate if text is filled in a userform.

Botje

New Member
Joined
Aug 23, 2011
Messages
48
How do i validate that there is "text" in my "txtbox"?

I tried to convert it from my "date-code" to:

Text
Word
Charactar
Data
IsString
And InStr

Rich (BB code):
 If Not IsWord(TxtNaam.Value) Then
    MsgBox "Vul Alsjeblieft een naam in."
    Exit Sub


What should i use instead of the "Word-code"?
I just cannot find it anywhere on google...

Rich (BB code):
Private Sub cmdinvullen_Click()
    If Me.TxtNaam.Value = "" Then
    MsgBox "Vul alsjeblieft je naam in.", vbExclamation, "Invulformulier Ideeën Bord"
    Me.TxtNaam.SetFocus
    Exit Sub
End If
    If Me.txtidee.Value = "" Then
    MsgBox "Vul alsjeblieft je idee in.", vbExclamation, "Invulformulier Ideeën Bord"
    Me.txtidee.SetFocus
    Exit Sub
End If
    If Not IsWord(TxtNaam.Value) Then
  MsgBox "Vul Alsjeblieft een naam in."
  Exit Sub
End If
    If Me.ComboBox1.Value = "" Then
    MsgBox "Vul alsjeblieft je team in.", vbExclamation, "Invulformulier Ideeën Bord"
    Me.ComboBox1.SetFocus
    Exit Sub
End If
   If Datum.Value = "" Then
  MsgBox "Vul alsjeblieft een datum in."
  Exit Sub
Else
    If Not IsDate(Datum.Value) Then
    MsgBox "Ongeldige datum ingevoerd."
    Exit Sub
End If
    If (Datum.Value <= Date$) Then
    MsgBox "Datum dient in de toekomst te liggen."
    Exit Sub
End If
End If
Dim Resp As Variant
    Resp = MsgBox("Je hebt de volgende informatie ingevoerd, klopt dit? " & vbNewLine & "Naam  :        " & Me.TxtNaam.Value & vbNewLine & "Team  :        " & Me.ComboBox1.Value & vbNewLine & "Idee    :        " & Me.txtidee.Value, vbYesNo + vbQuestion)
    If Resp = vbNo Then
                    Exit Sub
    Else
        MsgBox "Idee ingevoerd!"
 
End If
RowCount = Worksheets("Archief").Range("B1").CurrentRegion.Rows.Count
With Worksheets("Archief").Range("B1")
.Offset(RowCount, 14).Value = Me.TxtNaam.Value
.Offset(RowCount, 0).Value = Me.txtidee.Value
.Offset(RowCount, 15).Value = Me.ComboBox1.Value
If Me.chkTijd.Value = True Then
.Offset(RowCount, 19).Value = "X"
Else
.Offset(RowCount, 19).Value = ""
End If
If Me.chkGeld.Value = True Then
.Offset(RowCount, 20).Value = "X"
Else
.Offset(RowCount, 20).Value = ""
End If
If Me.chkCollegas.Value = True Then
.Offset(RowCount, 21).Value = "X"
Else
.Offset(RowCount, 21).Value = ""
End If
If Me.chkToestemming.Value = True Then
.Offset(RowCount, 22).Value = "X"
Else
.Offset(RowCount, 22).Value = ""
End If
If Me.chkRuimte.Value = True Then
.Offset(RowCount, 23).Value = "X"
Else
.Offset(RowCount, 23).Value = ""
End If
If Me.chkAnders.Value = True Then
.Offset(RowCount, 24).Value = "X"
Else
.Offset(RowCount, 24).Value = ""
End If
If Me.chkAchmeaVitale.Value = True Then
.Offset(RowCount, 1).Value = "X"
Else
.Offset(RowCount, 1).Value = ""
End If
If Me.chkKeuringen.Value = True Then
.Offset(RowCount, 2).Value = "X"
Else
.Offset(RowCount, 2).Value = ""
End If
If Me.chkKlantenservice.Value = True Then
.Offset(RowCount, 3).Value = "X"
Else
.Offset(RowCount, 3).Value = ""
End If
If Me.chkFrontoffice.Value = True Then
.Offset(RowCount, 4).Value = "X"
Else
.Offset(RowCount, 4).Value = ""
End If
If Me.chkExoten.Value = True Then
.Offset(RowCount, 5).Value = "X"
Else
.Offset(RowCount, 5).Value = ""
End If
If Me.chkMKB.Value = True Then
.Offset(RowCount, 6).Value = "X"
Else
.Offset(RowCount, 6).Value = ""
End If
If Me.chkDAM.Value = True Then
.Offset(RowCount, 7).Value = "X"
Else
.Offset(RowCount, 7).Value = ""
End If
If Me.chkBA.Value = True Then
.Offset(RowCount, 8).Value = "X"
Else
.Offset(RowCount, 8).Value = ""
End If
If Me.chkRAM.Value = True Then
.Offset(RowCount, 9).Value = "X"
Else
.Offset(RowCount, 9).Value = ""
End If
If Me.chkSAM.Value = True Then
.Offset(RowCount, 10).Value = "X"
Else
.Offset(RowCount, 10).Value = ""
End If
If Me.chkAMI.Value = True Then
.Offset(RowCount, 11).Value = "X"
Else
.Offset(RowCount, 11).Value = ""
End If
If Me.chkGMAT5.Value = True Then
.Offset(RowCount, 12).Value = "X"
Else
.Offset(RowCount, 12).Value = ""
End If
If Me.chkICO.Value = True Then
.Offset(RowCount, 13).Value = "X"
Else
.Offset(RowCount, 13).Value = ""
.Offset(RowCount, 16).Value = Format(Now, "dd/mm/yyyy hh:nn")
End If
.Offset(RowCount, 17).Value = DateValue(Datum.Text)
End With
    Unload Me
End Sub
Private Sub cmdsluiten_Click()
    Unload Me
End Sub
Private Sub UserForm_Click()
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What else would be in a TEXTbox?

If you type number in a textboxes it's text and if you want to see if it can be interpreted as a number you use IsNumeric.

Same with dates, but you validate with IsDate.

What is it you actually. want to check?

Is it the length of what's entered?

That it matches something?
 
Upvote 0
What else would be in a TEXTbox?

If you type number in a textboxes it's text and if you want to see if it can be interpreted as a number you use IsNumeric.

Same with dates, but you validate with IsDate.

What is it you actually. want to check?

Is it the length of what's entered?

That it matches something?

I think i used the wrong words.

What i mean is. I want to force people to use First And Last Name.

So its like "Name"SPACE"Lastname" and so on.
But i want to keep it in one line.
Same as i force people to use a date instead of a random number etc.

Do you understand what i mean now?
 
Upvote 0
Why not use 2 textboxes instead of one?

Or if you have a list of people use a combobox.
 
Upvote 0
How many names are there?

More than 20 is maybe a bit much.

As for putting the values in one cell.
Code:
Range("A1").Value = txtFirst.Value & " " & txtSecond.Value

Forgot to mention, you could have two comboboxes.

They could be cascading so the selection in the first narrows down the items in the second.

eg you have a list of surnames in one combobox, and in the other only first names with that surname are listed
 
Upvote 0
How many names are there?

More than 20 is maybe a bit much.

As for putting the values in one cell.
Code:
Range("A1").Value = txtFirst.Value & " " & txtSecond.Value

Forgot to mention, you could have two comboboxes.

They could be cascading so the selection in the first narrows down the items in the second.

eg you have a list of surnames in one combobox, and in the other only first names with that surname are listed


over 500 names probarly.. So no that won't work. And thnx for the other info.. im going to try that.
 
Upvote 0
20 was a typo actually, I meant 200.

Why do you think a combobox couldn't be used for that?
 
Upvote 0
20 was a typo actually, I meant 200.

Why do you think a combobox couldn't be used for that?

Well.. Ofcourse it could be used.. But you got to scroll down through 500 names.. that makes an Hugenormous list..
Rather have them typ it in theirselves.

I want the form easy to handle.. For them.. And low on maintenance for myself! :D

Trying to fix these 2 boxes.. ( Probarly going to take a while!:P )
 
Upvote 0
You don't need to scroll down in a combobox to select an item.

In fact you don't have to you use the dropdown at all, you can just type the name in.

Then it's easy to check that what's been typed is on the list by looking at the ListIndex of the combobox.

If its -1 then what they've typed isn't on the list.

Also a combobox set up so that a match is made to the first few characters, so they don't need to type the whole name.

What have you tried with the comboboxes?

It should be pretty straightforward, as long as you do have a list of names with surnames and first names in separate columns.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top