| | |
validaition check... urgent...
Thread Solved |
hey all!
please help me to check for validaiton such that... i hv few textboxes and combo boxes and if data is not entered in them then the submit button should be locked... and also tell me where should i write the code as in .... in form_load or submit_click... im confused... the code i wrote was...
thanks a tonne... plz do help!
good day!... enjoy programming!...
please help me to check for validaiton such that... i hv few textboxes and combo boxes and if data is not entered in them then the submit button should be locked... and also tell me where should i write the code as in .... in form_load or submit_click... im confused... the code i wrote was...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then MsgBox "Please fill all details" SUBMIT2(1).Enabled = False Else: SUBMIT2(1).Enabled = True End If
thanks a tonne... plz do help!
good day!... enjoy programming!...
Submit or Ok-button is the proper place to validate input. Since you have many things to validate, I would use a separate function:
and in the Submit or Ok-button validate:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Function ValidateForm() As Boolean ' Validate form fields If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then MsgBox "Please fill all details" ValidateForm = False Exit Function End If ValidateForm = True End Function
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command1_Click() ' Ok-button, validate before exit If ValidateForm Then ' Fields are ok, return from the form Me.Hide End If End Sub
Teme64 @ Windows Developer Blog
You can also make the function as common for all...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Public Function isAllFilledUp(frm As Form) As Boolean Dim ctrl As Control isAllFilledUp = True For Each ctrl in frm If TypeOf ctrl Is TextBox Then If ctrl = vbNullString Then isAllFilledUp = False Exit Function End If End If Next End Function
Last edited by jireh; Oct 13th, 2008 at 8:33 am.
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
•
•
Join Date: Jul 2008
Posts: 44
Reputation:
Solved Threads: 3
There are many ways to validate whether it is a text box or a button or submit button, the way you write the code and the place you put your code can be vary, depending upon your decision, one simple way is to write the validation code and make that code as public so that you can call it from any where and any time you need. Let me give you one example:
Public Sub ControlMyButton()
if MyText1.Text="" OR MyCombo.Text="" then
Submitbutton.enable=False
else
Submitbutton.enable=True
end if
End Sub
The above code can be easily called (Instead of writing in event of the form) like this:
Say in the KeyUp Event of the text Box:
Call ControlMyButton
Even, In the MyText1_Change, and in the form Load event you can called 'Call ControlMyButton'
So, Only when the textbox is filled, the button will be enabled.
I think this will give you an Idea. Try in different way. Its not difficult.
Public Sub ControlMyButton()
if MyText1.Text="" OR MyCombo.Text="" then
Submitbutton.enable=False
else
Submitbutton.enable=True
end if
End Sub
The above code can be easily called (Instead of writing in event of the form) like this:
Say in the KeyUp Event of the text Box:
Call ControlMyButton
Even, In the MyText1_Change, and in the form Load event you can called 'Call ControlMyButton'
So, Only when the textbox is filled, the button will be enabled.
I think this will give you an Idea. Try in different way. Its not difficult.
No. None of them is a complete solution and nobody can give one without seeing the whole code.
There may be a just a little spot everyone's missed. Can you give more details?
But few things to try out:
Text may contain spaces, so trim them off like
Then split your validation code to validate every control separately:
and tell us at which point validation fails and what was the input. You may do validation in any of the suggested places (Ok_Click, Form_Unload etc.).
There may be a just a little spot everyone's missed. Can you give more details?
But few things to try out:
Text may contain spaces, so trim them off like
Trim(cname.Text) = "" Then split your validation code to validate every control separately:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
If Trim(cname.Text) = "" Then MsgBox "Please fill all details (cname)" End If If Trim(empname2.Text) = "" Then MsgBox "Please fill all details (empname)" End If ... etc.
Teme64 @ Windows Developer Blog
Ok, I will just correct your code and make a little changes to make it more useful...
your code...
put your code in a function let's name it as isFilledUp()
Suppose you have a save button...
Huh! so much homework... Hope this would help you.
your code...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then MsgBox "Please fill all details" SUBMIT2(1).Enabled = False Else: SUBMIT2(1).Enabled = True End If
put your code in a function let's name it as isFilledUp()
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Function isFilledUp() As Boolean isFilledUp = True If Trim(cname.Text) = "" Then Msgbox "Please enter Customer Name." cname.SetFocus isFilledUp = False Exit Function End If If Trim(empname2.Text) = "" Then Msgbox "Please enter Employee Name." empname2.SetFocus isFilledUp = False Exit Function End If If Trim(reason2.Text) = "" Then Msgbox "Please enter reason." reason2.SetFocus isFilledUp = False Exit Function End If If Trim(days2.Text) = "" Then Msgbox "Please enter days." days2.SetFocus isFilledUp = False Exit Function End If If Trim(approval.Text = "Yes" Then Msgbox " " 'put your comment here. isFilledUp = False Exit Function End If End Function
Suppose you have a save button...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub btnSave_Click() If Not isFilledUp Then SUBMIT2(1).Enabled = False 'add your code here if not all were filled up Else SUBMIT2(1).Enabled = True 'add your code here if all are filled up End If End Sub
Huh! so much homework... Hope this would help you.
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
smile4evr said there are also combo boxes. Could the validation fail with combos?
Teme64 @ Windows Developer Blog
WT?!!! just replace the checking in textboxes to combo boxes... You guys still in school? think this is a homework... anyways...
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
•
•
Join Date: May 2008
Posts: 8
Reputation:
Solved Threads: 1
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dear I think I Solve Your Problime. When You Open Your Curent Form VB use Private sub Form1_load() endsub this Code is used for Form Load. When You Form Load You enter the following Code Private sub form1_load() text1.text="" text2.text="" text3.text="" text4.text="" Command1.Enable=false Msgbox "Enter All Deatiles && fill All Fileds",VBInformation,"Add Detailes" end Sub I Hope This Code Work Accourding To Your Problime
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Portability
- Next Thread: MS access DB- value of blank field
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





