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
 
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.


I have not tried the comboboxes.. because of
as long as you do have a list of names with surnames and first names in separate columns

Aint got that.. And Would take ages to recieve all the names because all the people are spread all over the country.. So that aint an option ( TO BAD )
Did use it for my department though. That did work great.

I guess i need to stick to 2 Textboxes. But i'll be fine!

Thanks alot for the thinking / responses!
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You don't need to have a complete list to start with, you can set things up so that if the user enters a name not on the current list it can be added to the list.

You can also easily add delete change the list when you need to, for example as you recieve the names from the other departments.

Anyway, if 2 textboxes are fine and work then stick with that.:)
 
Upvote 0
You don't need to have a complete list to start with, you can set things up so that if the user enters a name not on the current list it can be added to the list.

You can also easily add delete change the list when you need to, for example as you recieve the names from the other departments.

Anyway, if 2 textboxes are fine and work then stick with that.:)

Well if it aint to hard.. I am willing to try that:P haha. Since im only doing VBA/Excel since 1 week im a bit afraid it'll be a mess!

Got any links to tutorials for these items?
 
Upvote 0
You want to try starting with a small list and set things up to add names to it?

I don't know any tutorials for it, I'm sure there are, but I could post some code.

What would help would be a short list of names, not 'real' people of course.

Just something to work with.:)
 
Upvote 0
You want to try starting with a small list and set things up to add names to it?

I don't know any tutorials for it, I'm sure there are, but I could post some code.

What would help would be a short list of names, not 'real' people of course.

Just something to work with.:)

Jan
Kees
Klaas
Joost
Johan
Mieke
Karel
Gerard
Eduard
Richard
Ypsolon
Theo
Lianne
Anton
Bernard
Cornelis
Dirk
Esther

Thats a list of common dutch names:P what could you make of that?

PS:

End If
If (Datum.Value <= Date$) Then
MsgBox "Datum dient in de toekomst te liggen."
Exit Sub

This code must force people to enter a future date.. It Used to work but doesnt anymore.. Got a clue? Also tried with the
Format(Now, "dd/mm/yyyy")
 
Last edited:
Upvote 0
Is Datum a textbox?
Rich (BB code):
DateValue(Datum.Value)<=Date()
Not sure what you want with the data, is it just the adding new names part?
 
Upvote 0
Is Datum a textbox?
Rich (BB code):
DateValue(Datum.Value)<=Date()
Not sure what you want with the data, is it just the adding new names part?


Haha, i think i totally misunderstood you! :laugh:

But yea indeed that was for the "adding new names part".
(I figured you wanted a list of names so you could work something out.. haha)
 
Upvote 0
I was answering the questions backwards, to see if I can confuse you even more.:)

Actually, did you try what I posted for the date?

What you need to do is convert the text to a date and there are various ways to do it, I like to use DateValue.


What I didn't get was that it appears to be just a list of first names.

I was kind of expecting a few last names as well, even some duplicates.
 
Upvote 0
I was answering the questions backwards, to see if I can confuse you even more.:)

Actually, did you try what I posted for the date?

What you need to do is convert the text to a date and there are various ways to do it, I like to use DateValue.


What I didn't get was that it appears to be just a list of first names.

I was kind of expecting a few last names as well, even some duplicates.

The date thing did work! i used to have that but i think i accidentely deleted a part :rolleyes:

And for the name part:

Jan Veen
Kees Bruin
Klaas Klaassen
Joost Jansen
Johan De Vries
Mieke De Boer
Karel van Gelre
Gerard Vries
Eduard Van Der Steen
Richard van de Gaal
Ypsolon Vries
Theo Theorus
Lianne Lanninga
Anton Antonius
Bernard Bos
Cornelis de Dijk
Dirk van Dijck
Esther Bosch


That better?
 
Upvote 0
That's OK, could have done with some duplicates but I can do that myself.

I'll try and post something later to show how you can add names with that data as a starting list.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
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