Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript quick question 1

Status
Not open for further replies.

craigey

Technical User
Apr 18, 2002
510
GB
hi i have the following code to evaluate the age entered. Only problem is that if the dob entered is after todays date, then i get both error messages come up. How can i modify this code to end after displaying 1 or the other error.

thanks

Code:
Private Sub DOB_AfterUpdate()
Dim errr, BirthDate As Date
BirthDate = Date
errr = 0
If DOB > BirthDate Then
   MsgBox ("The Date Of Birth Cannot Be After Today!" & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & "That's Just Not Possible!" & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & "Please Check The Date Of Birth."), vbExclamation, "Ooopps....You Made A Mistake!"
   DOB.SetFocus
    errr = errr + 1
If errr = 1 Then End Sub
If age < 11 Or age > 22 Then
    MsgBox (&quot;Cadets Should Be At Least 13 Years Old.&quot; & (Chr(13) & Chr(10)) & &quot;And A Maximum Of 23 Years.&quot; & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & &quot;Please Check The Date Of Birth.&quot;), vbExclamation, &quot;Ooopps....You Made A Mistake!&quot;
    DOB.SetFocus
    errr = errr + 1
    End If
    End If
End Sub

I keep getting errors about end if's and end sub expected. I know what i'm trying to do, but just can't get this to work as i want it to.

Please help!!
 
At a first look...
This is wrong:
If errr = 1 Then End Sub

This is right:
If errr = 1 Then Exit Sub

HTH
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Thanks, Got it working. I had to make one more subtle change. Didn't to bad though as it is 7am (in the uk), and was about 5am when i tried coding!

Here's the revised code, for those who are interested.
Code:
Private Sub DOB_AfterUpdate()
Dim errr, BirthDate As Date
BirthDate = Date
errr = 0
If DOB > BirthDate Then
   MsgBox (&quot;The Date Of Birth Cannot Be After Today!&quot; & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & &quot;That's Just Not Possible!&quot; & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & &quot;Please Check The Date Of Birth.&quot;), vbExclamation, &quot;Ooopps....You Made A Mistake!&quot;
   DOB.SetFocus
    errr = errr + 1
If errr = 1 Then Exit Sub
Else
Code:
If age < 11 Or age > 22 Then
    MsgBox (&quot;Cadets Should Be At Least 13 Years Old.&quot; & (Chr(13) & Chr(10)) & &quot;And A Maximum Of 23 Years.&quot; & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & &quot;Please Check The Date Of Birth.&quot;), vbExclamation, &quot;Ooopps....You Made A Mistake!&quot;
    DOB.SetFocus
    errr = errr + 1
    End If
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top