Results 1 to 6 of 6
  1. #1
    Sephaerius is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2013
    Posts
    62

    DCount odd numbers

    Can DCount capture odd numbers of rows? What I'm after is a DCount formula to count the number of rows, and if that value returns as an odd number, to then do stuff. so it would look something like this:



    Code:
    If DCount("[Account Number]", TDF.Name) [is an odd number] Then
    'do stuff
    End If
    I just don't know what to put in place of [is an odd number].

    Can this be done?

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try:
    Code:
        If DCount("[Account Number]", TDF.Name) = 1 Then
            MsgBox "Is odd"
        Else
            MsgBox "Is even"
        End If

  3. #3
    Sephaerius is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2013
    Posts
    62
    Quote Originally Posted by JoeM View Post
    Try:
    Code:
        If DCount("[Account Number]", TDF.Name) = 1 Then
            MsgBox "Is odd"
        Else
            MsgBox "Is even"
        End If
    Will this also work for DCounts that equal 3, 5, 7, 9, etc?

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    DOH! Not, if I don't give you the right code!
    Sorry, I left an important piece off.

    It should be:
    Code:
        If DCount("[Account Number]", TDF.Name) Mod 2 = 1 Then
            MsgBox "Is odd"
        Else
            MsgBox "Is even"
        End If
    That returns the remainder of your DCOUNT when divided by 2 (odd numbers always have a remainder of 1 when divided by 2).

  5. #5
    Sephaerius is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2013
    Posts
    62
    Quote Originally Posted by JoeM View Post
    DOH! Not, if I don't give you the right code!
    Sorry, I left an important piece off.

    It should be:
    Code:
        If DCount("[Account Number]", TDF.Name) Mod 2 = 1 Then
            MsgBox "Is odd"
        Else
            MsgBox "Is even"
        End If
    That returns the remainder of your DCOUNT when divided by 2 (odd numbers always have a remainder of 1 when divided by 2).
    Thanks, looks like that does the trick!

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome.

    If you wanted to specifically look for even numbers, just use:
    Code:
    DCount(...) Mod 2 = 0

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

Similar Threads

  1. Replies: 2
    Last Post: 08-30-2017, 07:11 AM
  2. Replies: 1
    Last Post: 03-17-2017, 06:08 PM
  3. Replies: 4
    Last Post: 06-24-2014, 10:49 AM
  4. Replies: 8
    Last Post: 03-10-2014, 11:47 AM
  5. Replies: 1
    Last Post: 11-29-2011, 08:43 AM

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