|
-
May 5th, 2003, 02:40 PM
#1
Thread Starter
Junior Member
textboxes not empty
I have 18 textboxes on my form. The user is not allowed to exit form without filling all the textboxes. At the moment I am using:
Code:
If txtKlant_nummer.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtKlant_nummer.SetFocus
ElseIf txtKlantnaam.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtKlantnaam.SetFocus
ElseIf txtPostadres.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtPostadres.SetFocus
ElseIf txtWoonplaats.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtWoonplaats.SetFocus
ElseIf txtPostcode.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtPostcode.SetFocus
ElseIf txtLand.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtLand.SetFocus
ElseIf txtBTW_nummer.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtBTW_nummer.SetFocus
ElseIf txtTelefoon.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtTelefoon.SetFocus
ElseIf txtTelefoon2.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtTelefoon2.SetFocus
ElseIf txtFaxnummer.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtFaxnummer.SetFocus
ElseIf txtFaxnummer2.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtFaxnummer2.SetFocus
ElseIf txtMobieletelefoon.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtMobieletelefoon.SetFocus
ElseIf txtEmail_adres.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtEmail_adres.SetFocus
ElseIf txtNotitie_factuur.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtNotitie_factuur.SetFocus
ElseIf txtNotitie_factuur_2.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtNotitie_factuur_2.SetFocus
ElseIf txtOpslagpercentage.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtOpslagpercentage.SetFocus
ElseIf txtCommissie.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtCommissie.SetFocus
ElseIf txtDagen.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtDagen.SetFocus
Else
BlaBla
end if
At the moment it isn't working because after the msgbox the sub doesn't go to the blabla but exits the sub. And isn't there a cleaner way??
Thanks,
Brian
Homer no function beer well without.
--Homer Simpson
-
May 5th, 2003, 02:47 PM
#2
Use the validate event and set CausesValidation to True on each text box and the command button for exit. That should ensure that the textboxes have values.
Last edited by leinad31; May 5th, 2003 at 02:52 PM.
-
May 5th, 2003, 02:50 PM
#3
You might want to add Len(Textbox.Text) = 0 and Isnull() to the condition in case its not empty or is Null. I don't think strings can be IsEmpty() but I might be wrong.
Last edited by leinad31; May 5th, 2003 at 03:00 PM.
-
May 5th, 2003, 03:01 PM
#4
Member
just add "exit sub" right after each .setfocus
example
If txtKlant_nummer.Text = Empty Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtKlant_nummer.SetFocus
exit sub
ElseIf txtKlantnaam.Text = Empty Then
.....
.....
this way, the users can enter the info after the message is prompt when the text box is empty. When the box is not empty, it will carry on and check the next box.
-
May 5th, 2003, 03:18 PM
#5
Originally posted by ting2000
just add "exit sub" right after each .setfocus
If there's no code after the gigantic IF structure then there's no need for Exit Sub. If there's code after the IF struct that he needs to skip over then he'll need the Exit Sub. Anyway, he can do away with the IF ELSEIF struct if he makes use the Validate event instead. He can even call it locally in the form if he wants to.
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call Textbox1_Validate(True)
End Sub
-
May 5th, 2003, 03:19 PM
#6
-
May 5th, 2003, 03:31 PM
#7
Maybe its initialized to a zero length string and not Empty
-
May 5th, 2003, 03:44 PM
#8
Thread Starter
Junior Member
Dear manavo11
I don't know why it isn't working, to be honest i copied and paste it from a early project of mine and it works in there but for some reason it doesn't in this project. maybe leinad31 is right I have to check that.
I tried with the F8 and running the program but as soon as gives the first msgbox it leaves the sub.
But I was looking for a shorter way.
But thanks everybody,
Brian
Homer no function beer well without.
--Homer Simpson
-
May 5th, 2003, 04:03 PM
#9
If there aren't any other textboxes on the form you can do something like this (I haven't tested it) :
VB Code:
Private Sub Command1_Click()
Dim ctl As Control
For Each ctl In Form1
If TypeOf ctl Is TextBox Then
If ctl.Text = "" Then
ctl.SetFocus
MsgBox "EMPTY!"
Exit Sub
End If
End If
Next
MsgBox "ALL ARE FULL!"
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
May 5th, 2003, 04:04 PM
#10
Junior Member
This SHOULD work.
VB Code:
Private Sub Form_Unload(Cancel As Integer)
If txtKlant_nummer.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtKlant_nummer.SetFocus
ElseIf txtKlantnaam.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtKlantnaam.SetFocus
ElseIf txtPostadres.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtPostadres.SetFocus
ElseIf txtWoonplaats.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtWoonplaats.SetFocus
ElseIf txtPostcode.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtPostcode.SetFocus
ElseIf txtLand.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtLand.SetFocus
ElseIf txtBTW_nummer.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtBTW_nummer.SetFocus
ElseIf txtTelefoon.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtTelefoon.SetFocus
ElseIf txtTelefoon2.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtTelefoon2.SetFocus
ElseIf txtFaxnummer.Text ="" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtFaxnummer.SetFocus
ElseIf txtFaxnummer2.Text =""Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtFaxnummer2.SetFocus
ElseIf txtMobieletelefoon.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtMobieletelefoon.SetFocus
ElseIf txtEmail_adres.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtEmail_adres.SetFocus
ElseIf txtNotitie_factuur.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtNotitie_factuur.SetFocus
ElseIf txtNotitie_factuur_2.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtNotitie_factuur_2.SetFocus
ElseIf txtOpslagpercentage.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtOpslagpercentage.SetFocus
ElseIf txtCommissie.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtCommissie.SetFocus
ElseIf txtDagen.Text = "" Then
Call MsgBox("Alle velden invullen.", vbExclamation + vbDefaultButton1, "Let Op!")
txtDagen.SetFocus
Else
BlaBla
end if
End Sub
add an exit sub after each message box call.
-
May 6th, 2003, 01:21 PM
#11
Thread Starter
Junior Member
stupid me
I think I have found my problem
I have placed this code in the form_unload when I code "exit sub" it stil does form unload.
I am going to make a button which ends the form.
And I like the simplicity of the answer of manavo11 with the loop thrue the textboxes.
Thanks everybody,
Brian
Homer no function beer well without.
--Homer Simpson
-
May 6th, 2003, 03:39 PM
#12
If you want to avoid the form from unloading in the form_unload event all you have to do is set the cancel value to something (anything) other than zero. Like this (you can hit the X button all you want or a button with unload me in it and it won't close the form. It will if you put "End" in it.) :
VB Code:
Private Sub Form_Unload(Cancel As Integer)
Cancel = 3
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
May 6th, 2003, 04:00 PM
#13
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|