Results 1 to 6 of 6
  1. #1
    dolovenature is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2012
    Posts
    14

    Question Age validation

    Hi,
    I am absolutely novice in access, and i am entrusted with a responsibility.
    My Problem is.....
    I have a FORM(form1) related to a table(table1).
    While entering data using the FORM if the AGE field is less than 18 then a Message box would appear "Age is not valid" with only one button is the box "Ok",
    If the user click OK it will return to the FORM.
    can anybody help with the code?



    Regards
    saikat

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by dolovenature View Post

    ...can anybody help with the code?
    I'm sure we can, if you'll re-post your problem as a new thread! Placing your post here, on someone else's thread, is considered highjacking and is frowned upon, not only here but on all forums. Be sure to give your thread a descriptive title, such as 'Age validation with warning message.'

    Looking forward to hearing from you!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I split this out to a new thread.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    dolovenature is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2012
    Posts
    14
    Thanks Everybody,

    It was my ignorance about this forum...sorry..

    Saikat

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, and welcome to the site!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Is the age being entered by the user or is the date of birth being entered and you need to calculate the age and pop up your warning based on that?

    If the former is the case, this will do it:
    Code:
    Private Sub txtAgeField_BeforeUpdate(Cancel As Integer)
     If Me.txtAgeField < 18 Then
      MsgBox "Age is not valid"
      Cancel = True
      txtAgeField.SelStart = 0
      txtAgeField.SelLength = Len(Me.txtAgeField)
     End If
    End Sub

    If the DOB is being entered, this modification will work:

    Code:
    Private Sub txtDOB_BeforeUpdate(Cancel As Integer)
     
    Dim TrueAge As Integer
       
    If Nz(Me.txtDOB, "") <> "" Then
    
    TrueAge = DateDiff("yyyy", [txtDOB], Date) + Int(Format(Date, "mmdd") < Format([txtDOB], "mmdd"))
    
     If TrueAge < 18 Then
      Cancel = True
      txtDOB.SelStart = 0
      txtDOB.SelLength = Len(Me.txtDOB)
      MsgBox "Age is not valid"
     End If
    
    End If
    
    End Sub


    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Age Validation with Message Box
    By dolovenature in forum Programming
    Replies: 3
    Last Post: 08-26-2012, 12:52 PM
  2. Date Validation for a course
    By Arrrggggjhhhhh!!!! in forum Forms
    Replies: 2
    Last Post: 03-02-2012, 02:07 AM
  3. validation
    By slimjen in forum Forms
    Replies: 6
    Last Post: 10-12-2011, 01:19 PM
  4. Data Validation using VBA
    By Cheshire101 in forum Programming
    Replies: 3
    Last Post: 05-10-2011, 08:43 AM
  5. Validation Rule
    By ritzzy in forum Access
    Replies: 1
    Last Post: 04-13-2011, 01:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums