Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152
    Thanks.

    Yes I want them to answer a year.

    So they would input i.e. 2015 which would be ok to continue.
    But if they answered <2011 then I want the first msgbox to appear stating <current year. And if they answered 2040 then this exceeds the life expectancy given an install of 2011 + 20 = 2031 so anything entered above 2031 would flag up the second message Exceeds Life Expectancy.



    But the first message flags up regardless of the answer

  2. #17
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, if you are just expecting a year input then you just need to run code as follows:

    Code:
    Dim vEntranceDoors
    Dim vCompareDate
    Dim vCurrDate
    
    vCurrDate = DatePart("yyyy", Date)
    vCompareDate = DatePart("yyyy", Date) + 20
    vEntranceDoors = EntranceDoorsFlatsRenewYear.Value
    If vEntranceDoors < vCurrDate Then
         MsgBox "Renew Year Invalid:  < Current Year!"
    End If
    If vEntranceDoors >= vCompareDate Then
         MsgBox "Renew Year Invalid:  Exceeds Life Expectancy!"
    End If
    This should work...

  3. #18
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152
    Ta.
    But now its doing the opposite. It now flags up the Exceeds Life Expectancy Msgbox regardless of the answer.

  4. #19
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, what is happening is this. Since you are going strictly off year you should treat these years as numbers not dates. Format EntranceDoorsFlatsRenewYear as a Fixed number with 0 decimal places. Dim all your variables as Long (See code below). This should work as expected. Make sure you save all changes before testing the code.

    Code:
    Dim vEntranceDoors, vCompareDate, vCurrDate As Long
    
    vCurrDate = DatePart("yyyy", Date)
    vCompareDate = DatePart("yyyy", Date) + 20
    vEntranceDoors = EntranceDoorsFlatsRenewYear.Value
    If vEntranceDoors < vCurrDate Then
         MsgBox "Renew Year Invalid:  < Current Year!"
    End If
    If vEntranceDoors >= vCompareDate Then
         MsgBox "Renew Year Invalid:  Exceeds Life Expectancy!"
    End If

  5. #20
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152
    Sorry still no luck.

    I have attached an example.

  6. #21
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152
    RESOLVED:
    Code:
    Private Sub EntranceDoorsFlatsRenewYear_AfterUpdate()
    If IsNull(EntranceDoorsFlatsRenewYear.Value) Then
        Me.[EntranceDoorsFlatsRenewYear] = ""
    ElseIf Me.[EntranceDoorsFlatsRenewYear] < Format(Date, "yyyy") Then
        MsgBox "Renew Year Invalid:  Less than current year!"
    ElseIf CLng(Me.[EntranceDoorsFlatsRenewYear] >= CLng(Format(Date, "yyyy") + 20)) Then
        MsgBox "Renew Year Invalid:  Exceeds life expectancy!"
    End If
    End Sub

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Validation Rule
    By Megan in forum Access
    Replies: 1
    Last Post: 11-05-2010, 09:45 AM
  2. Validation Rule
    By Christopher in forum Forms
    Replies: 15
    Last Post: 04-20-2010, 06:05 AM
  3. Validation Rule
    By robomose in forum Access
    Replies: 1
    Last Post: 09-09-2009, 05:59 AM
  4. Validation Rule
    By smitstev in forum Access
    Replies: 5
    Last Post: 06-30-2009, 09:58 AM
  5. Validation Rule
    By mistaken_myst in forum Database Design
    Replies: 2
    Last Post: 10-29-2007, 02:08 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