Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Proper Validation Structure? (a2k (9.0.6926) SP-3 Jet 4.0 SP-7)

    The following validation works OK, I have multiple formats si I need to do this in code

    Is there a more proper way to structure this code?

    How would I also check for Year to include next and previous year, Format(Date, "yyyy") + 1 and Format(Date, "yyyy")

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Proper Validation Structure? (a2k (9.0.6926) SP-3 Jet 4.0 SP-7)

    By using ElseIf (without a space between Else and If), you can get rid of 3 of the 4 End If's:

    If Condition1 Then
    ...
    ElseIf Condition2 Then
    ...
    ElseIf Condition3 Then
    ...
    ElseIf Condition4 Then
    ...
    End If

    Instead of Format(Date, "yyyy") you can use Year(Date). For next year, use (Year(Date) + 1), and for last year (Year(Date) - 1).

    You can use IsNumeric to test of a string represents a number:

    If Not IsNumeric(Mid(strRefNo, 6, 3)) Then
    ...

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper Validation Structure? (a2k (9.0.6926) SP-3 Jet 4.0 SP-7)

    Hans

    Maybe I have been looking at this too long.

    I
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Proper Validation Structure? (a2k (9.0.6926) SP-3 Jet 4.0 SP-7)

    John,

    This is because you are comparing strings to numbers. Use

    ElseIf Val(Left(strRefNo, 4)) < (Year(Date) - 1) Then

    and

    ElseIf Val(Left(strRefNo, 4)) > (Year(Date) + 1) Then

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper Validation Structure? (a2k (9.0.6926) SP-3 Jet 4.0 SP-7)

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •