-
Sep 3rd, 2014, 01:44 AM
#1
Thread Starter
Member
[RESOLVED] Validating multiple inputs on a form
I have a form where I have several textboxes for inputing data. The form is called by another program and when the data have been input and validated, the form should be closed and control returned to the calling program.
I want to validate the data in the boxes before closing it.
Here is the code I have for the form. The validation works as I want it (tho I am sure it could be more efficiently written):
Code:
Private Sub cmdCancel_Click()
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
ValidateControls
If Err = 380 Then
Cancel = True
End If
End Sub
Private Sub min_sep_Validate(Cancel As Boolean)
sepmin = Val(min_sep.Text)
If min_sep.Text = "" Or sepmin <= 0 Then
With min_sep
.SelStart = 0
.SelLength = Len(min_sep.Text)
.SetFocus
End With
MsgBox "Min separation must be a number > 0", vbExclamation, ""
Cancel = True
End If
End Sub
Private Sub max_sep_Validate(Cancel As Boolean)
sepmax = Val(max_sep.Text)
sepmin = Val(min_sep.Text)
If max_sep.Text = "" Or sepmax <= 0 Then
With max_sep
.SelStart = 0
.SelLength = Len(max_sep.Text)
.SetFocus
End With
MsgBox "Maximum separation must be a number > 0", vbExclamation, ""
Cancel = True
End If
If sepmax <= sepmin Then
With max_sep
.SelStart = 0
.SelLength = Len(max_sep.Text)
.SetFocus
End With
MsgBox "Maximum separation must be > minimum separation"
Cancel = True
End If
End Sub
When I click a Submit button I have on the form, the validation starts and after the validations have been done, the form stays there and I don't know how to progress. The only thing I can do is manually close the form or use a Cancel button I put on the form - and then control does not go back to the calling program.
Could someone help please?
-
Sep 3rd, 2014, 02:19 AM
#2
Thread Starter
Member
Re: Validating multiple inputs on a form
When I add
Code:
Private Sub cmdSubmit_Click()
End
End Sub
to the form, and click the Submit button, validation takes places and then the form is closed and the program ends - control does not return to the calling program.
-
Sep 3rd, 2014, 02:22 AM
#3
Re: Validating multiple inputs on a form
You know you can always unload the Form when the validations has finished. You can unload it in the called Form or the calling Form
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 3rd, 2014, 02:23 AM
#4
Re: Validating multiple inputs on a form
Originally Posted by hunter55
When I add
Code:
Private Sub cmdSubmit_Click()
End
End Sub
to the form, and click the Submit button, validation takes places and then the form is closed and the program ends - control does not return to the calling program.
What is this? Never use the End statement. That's what is messing things up. Use Unload as in Unload frmValidate, for example
Code:
Private Sub cmdSubmit_Click()
'
' Do what you have to do to call the validation code
'
Unload frmValidate
End Sub
Last edited by jmsrickland; Sep 3rd, 2014 at 02:27 AM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 3rd, 2014, 02:27 AM
#5
Re: Validating multiple inputs on a form
Often it makes far more sense to use Hide than Unload.
-
Sep 3rd, 2014, 02:30 AM
#6
Re: Validating multiple inputs on a form
Originally Posted by dilettante
Often it makes far more sense to use Hide than Unload.
Maybe
If you load a Form and run some processing for a one time only then you might as well unload it when finished. No sense in letting it hang around if you are not going to use it again. If you call subs in that Form several times throughout your session then OK, hide it but in either event you still have to use .Show to make it shown again. The important thing is you have to make sure you unload it when your app needs to be closed
Last edited by jmsrickland; Sep 3rd, 2014 at 11:36 AM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 3rd, 2014, 02:35 AM
#7
Thread Starter
Member
Re: Validating multiple inputs on a form
Thanks for your help. I have used Hide in the form then Unload later in the calling program
-
Sep 3rd, 2014, 12:37 PM
#8
Re: [RESOLVED] Validating multiple inputs on a form
I must admit, I don't see a reason to use hide instead of unload.
-
Sep 3rd, 2014, 01:25 PM
#9
Re: [RESOLVED] Validating multiple inputs on a form
I don't either. Hiding a Form doesn't make it any easier to show it again than unloading it. If you hide a Form and want it again shown you use Form1.Show and you do the same if you unload it. .Show will load a Form if it is not already loaded.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
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
|