Results 1 to 3 of 3
  1. #1
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23

    VBA If with multiple conditions

    I am trying to validate, in the after update event, an unbound form text box to make sure it is not null and has a four digit year if the default value "current year" is changed. Here is my code I have been trying but it doesn't seem to be working properly. Does anyone see what I am doing wrong? I can get it to validate if I use two separate statements however I end up with two messages which is not desired. Also is after update the appropriate place to put this and is there a better condition I can use for year. Thanks



    Code:
    Private Sub Year_AfterUpdate()
    If Not IsNumeric(Me.Year) And Me.Year <> 4 Then
    MsgBox "Please enter a four digit year."
    Cancel = True
    Me.Year.SetFocus
    End If
    End Sub

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    has a four digit year
    Then instead of:
    Code:
    Me.Year <> 4
    you want:
    Code:
    Len(Me.Year) <> 4

  3. #3
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23
    Thank You, knew I was missing something, except I put it on the Lost Focus event

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

Similar Threads

  1. Queries with multiple conditions
    By dccjr in forum Queries
    Replies: 3
    Last Post: 11-08-2013, 12:57 AM
  2. Replies: 3
    Last Post: 08-01-2012, 10:56 AM
  3. Using iif for Multiple Conditions
    By kwilbur in forum Access
    Replies: 5
    Last Post: 12-30-2011, 01:52 PM
  4. iif statement with multiple conditions
    By ragsgold in forum Queries
    Replies: 7
    Last Post: 08-24-2011, 05:38 PM
  5. Expression with multiple conditions
    By techexpressinc in forum Queries
    Replies: 3
    Last Post: 06-19-2009, 08: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