943,754 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Oct 12th, 2008
0

validaition check... urgent...

Expand Post »
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...


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2.  
  3. If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
  4. MsgBox "Please fill all details"
  5. SUBMIT2(1).Enabled = False
  6. Else: SUBMIT2(1).Enabled = True
  7. End If


thanks a tonne... plz do help!
good day!... enjoy programming!...
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
smile4evr is offline Offline
53 posts
since Aug 2008
Oct 12th, 2008
0

Re: validaition check... urgent...

Submit or Ok-button is the proper place to validate input. Since you have many things to validate, I would use a separate function:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Function ValidateForm() As Boolean
  2. ' Validate form fields
  3. If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
  4. MsgBox "Please fill all details"
  5. ValidateForm = False
  6. Exit Function
  7. End If
  8. ValidateForm = True
  9.  
  10. End Function
and in the Submit or Ok-button validate:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. ' Ok-button, validate before exit
  3. If ValidateForm Then
  4. ' Fields are ok, return from the form
  5. Me.Hide
  6. End If
  7. End Sub
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Oct 13th, 2008
0

Re: validaition check... urgent...

You can also make the function as common for all...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Function isAllFilledUp(frm As Form) As Boolean
  2. Dim ctrl As Control
  3.  
  4. isAllFilledUp = True
  5. For Each ctrl in frm
  6. If TypeOf ctrl Is TextBox Then
  7. If ctrl = vbNullString Then
  8. isAllFilledUp = False
  9. Exit Function
  10. End If
  11. End If
  12. Next
  13. End Function
Last edited by jireh; Oct 13th, 2008 at 8:33 am.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Oct 13th, 2008
0

Re: validaition check... urgent...

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.
Reputation Points: 10
Solved Threads: 4
Light Poster
K.Vanlalliana is offline Offline
44 posts
since Jul 2008
Oct 14th, 2008
0

Re: validaition check... urgent...

thanks a lot for the responses... but its not working... i tried each of them invidually... but it is not working...
sorry... pls do keep helping!
thnx!
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
smile4evr is offline Offline
53 posts
since Aug 2008
Oct 14th, 2008
0

Re: validaition check... urgent...

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 Trim(cname.Text) = ""
Then split your validation code to validate every control separately:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If Trim(cname.Text) = "" Then
  2. MsgBox "Please fill all details (cname)"
  3. End If
  4. If Trim(empname2.Text) = "" Then
  5. MsgBox "Please fill all details (empname)"
  6. End If
  7. ... etc.
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.).
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Oct 14th, 2008
0

Re: validaition check... urgent...

Ok, I will just correct your code and make a little changes to make it more useful...

your code...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
  2. MsgBox "Please fill all details"
  3. SUBMIT2(1).Enabled = False
  4. Else: SUBMIT2(1).Enabled = True
  5. End If

put your code in a function let's name it as isFilledUp()

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Function isFilledUp() As Boolean
  2. isFilledUp = True
  3.  
  4. If Trim(cname.Text) = "" Then
  5. Msgbox "Please enter Customer Name."
  6. cname.SetFocus
  7. isFilledUp = False
  8. Exit Function
  9. End If
  10.  
  11. If Trim(empname2.Text) = "" Then
  12. Msgbox "Please enter Employee Name."
  13. empname2.SetFocus
  14. isFilledUp = False
  15. Exit Function
  16. End If
  17.  
  18. If Trim(reason2.Text) = "" Then
  19. Msgbox "Please enter reason."
  20. reason2.SetFocus
  21. isFilledUp = False
  22. Exit Function
  23. End If
  24.  
  25. If Trim(days2.Text) = "" Then
  26. Msgbox "Please enter days."
  27. days2.SetFocus
  28. isFilledUp = False
  29. Exit Function
  30. End If
  31.  
  32. If Trim(approval.Text = "Yes" Then
  33. Msgbox " " 'put your comment here.
  34. isFilledUp = False
  35. Exit Function
  36. End If
  37. End Function

Suppose you have a save button...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub btnSave_Click()
  2. If Not isFilledUp Then
  3. SUBMIT2(1).Enabled = False
  4. 'add your code here if not all were filled up
  5. Else
  6. SUBMIT2(1).Enabled = True
  7. 'add your code here if all are filled up
  8. End If
  9. End Sub

Huh! so much homework... Hope this would help you.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Oct 14th, 2008
0

Re: validaition check... urgent...

smile4evr said there are also combo boxes. Could the validation fail with combos?
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Oct 14th, 2008
0

Re: validaition check... urgent...

WT?!!! just replace the checking in textboxes to combo boxes... You guys still in school? think this is a homework... anyways...
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Oct 15th, 2008
0

Re: validaition check... urgent...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dear I think I Solve Your Problime.
  2. When You Open Your Curent Form VB use
  3.  
  4. Private sub Form1_load()
  5.  
  6. endsub
  7.  
  8. this Code is used for Form Load. When You Form Load You enter the following Code
  9.  
  10. Private sub form1_load()
  11. text1.text=""
  12. text2.text=""
  13. text3.text=""
  14. text4.text=""
  15. Command1.Enable=false
  16. Msgbox "Enter All Deatiles && fill All Fileds",VBInformation,"Add Detailes"
  17. end Sub
  18.  
  19.  
  20. I Hope This Code Work Accourding To Your Problime
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Bhatti302 is offline Offline
8 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Portability
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: MS access DB- value of blank field





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC