Results 1 to 3 of 3
  1. #1
    bfont is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    5

    Using AND with OR in IF statement

    Hello,

    Can someone tell me what is wrong with the code below? The section before "And" is not being evaluated.

    Private Sub Form_BeforeUpdate(Cancel As Integer)


    Dim strMsg As String
    If cboActivityID.Value = "P" And EndTime.Value = "0" Or IsNull(Me.EndTime.Value) = True Then
    Cancel = True
    strMsg = strMsg & "End Time required." & vbCrLf

    End If


    Thank you for your help

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use parens to manage the order of operations. Which logic do you want? Possibly:

    If Me.cboActivityID = "P" And (Me.EndTime = "0" Or IsNull(Me.EndTime)) Then

    or

    If (Me.cboActivityID = "P" And Me.EndTime = "0") Or IsNull(Me.EndTime) Then

    Value is default property of data controls. Don't need to type.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bfont is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    5
    Thank you!

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

Similar Threads

  1. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  2. iif Statement Help
    By smc678 in forum Forms
    Replies: 8
    Last Post: 12-11-2012, 11:02 AM
  3. In Statement
    By tobe in forum Access
    Replies: 1
    Last Post: 12-04-2012, 02:11 PM
  4. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  5. Replies: 7
    Last Post: 08-17-2011, 01:49 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