Results 1 to 6 of 6
  1. #1
    Dominaz is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    21

    Using DCount with Long integer


    Hello!
    I'm having problems Using Dcount function, when I use it with a text field like the following it works fine: (but using a Surname as a criteria can have problems.... I've people with the same surname in my database...)

    times = DCount("[Surname]", "Booktoscore", "[Surname] = Forms!Teachers!Surname.value")


    But, If I try to use it with a number, then it doesn't work, the problem seems to be with the criteria.... Because Access don't show me any msgbox with errors....

    times = DCount("[IdCandidate]", "Booktoscore", "[IdCandidate] = Forms!Teachers!IdCandidate.Value")


    Thank you very much!!!

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    With the DCount() function you can use the * wildcard instead of a specific field since you are just counting records. The main issue with your expression is that the form references a variable and thus cannot be contained within the double quotes

    times = DCount("[Surname]", "Booktoscore", "[Surname] =" & Forms!Teachers!Surname.value)

    OR

    times = DCount("*", "Booktoscore", "[Surname] =" & Forms!Teachers!Surname.value)

  3. #3
    Dominaz is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    21
    HelloĦ Thanks for your help, but I think you didn´t understand me,

    When I use :

    times = DCount("[Surname]", "Booktoscore", "[Surname] = Forms!Teachers!Surname.value")

    It works. (Surnname is a text)

    BUT when I try to use:

    times = DCount("[IdCandidate]", "Booktoscore", "[IdCandidate] = Forms!Teachers!IdCandidate.Value")

    It doesn´t works... IdCandidate is a number....

    Thanks again

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    The reference to the form (no matter what field type) must no be included within the double quotes.



    Sorry, I did forgot to delimit the text field. Text fields must be delimited by single quotes and if the value is a variable like your form reference it must not be in the double quotes. Note the single quotes in blue and the placement of the double quotes and the &'s

    times = DCount("*", "Booktoscore", "[Surname] ='" & Forms!Teachers!Surname.value & "'")


    Numeric fields do not have to be delimited but the form reference still has to be outside the double quotes and connected to the string with an &

    times = DCount("*", "Booktoscore", "[IdCandidate] =" & Forms!Teachers!IdCandidate)

    Also if you are counting you can use the * wildcard in place of the field since the Dcount just counts records irrespective of the field.

  5. #5
    Dominaz is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    21
    Thank very much. Now It works !!

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome

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

Similar Threads

  1. How to Set an Integer to Nothing
    By orcinus in forum Programming
    Replies: 4
    Last Post: 05-17-2011, 11:21 AM
  2. Integer not incrementing
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 01-31-2011, 02:40 PM
  3. Adding column as INTEGER makes it a long integer?
    By luckycharms in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 02:47 PM
  4. How to ADD integer (vba)
    By Computer202 in forum Programming
    Replies: 24
    Last Post: 03-13-2010, 08:50 AM
  5. Replies: 3
    Last Post: 04-12-2009, 05:11 PM

Tags for this Thread

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