Results 1 to 6 of 6
  1. #1
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528

    DCount error

    Hello guys


    I have a form I've put into it unstructured text field I've put into it this expression, but it appears there is an error
    = DCount ("*"; "tblMaster"; "(Rank = 'Dean' OR Rank = 'colonel' OR Rank = 'provider' OR Rank = 'pioneer' OR Rank = 'captain' OR Rank = 'first lieutenant' OR Rank = 'lieutenant') ")

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try replacing the semi-colons with commas.
    Does this error out?
    Code:
    = DCount ("*", "tblMaster", "Rank = 'Dean' ")
    If not, starting adding in the criteria one at a time.

  3. #3
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Thank you
    When you change the interval semicolon show me this message
    Is it possible to convert them to function sub in vba
    It works well on the report
    Attached Thumbnails Attached Thumbnails ddd.JPG  

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Oops, I forgot about international settings. You are right - need to use semi-colons.

    It works well on the report
    If it works in a report, it should work on a form.
    Does this cause an error?
    Code:
    = DCount ("*"; "tblMaster"; "Rank = 'Dean' ")

    Yes, is could be converted to a VBA function. Something like this:
    Code:
    Public Function CountRanks() As Integer
        Dim r As DAO.Recordset
        Dim sSQL As String
        Dim RC As Integer   ' RC = record count
    
        RC = 0
    
        sSQL = "SELECT Rank FROM tblMaster"
        sSQL = sSQL & " WHERE Rank = 'Dean' OR Rank = 'colonel' OR Rank = 'provider' OR"
        sSQL = sSQL & " Rank = 'pioneer' OR Rank = 'captain' OR Rank = 'first lieutenant' OR Rank = 'lieutenant'"
    
        Set r = CurrentDb.OpenRecordset(sSQL)
        If Not (r.BOF And r.EOF) Then
            r.MoveLast
            RC = r.RecordCount
        End If
    
        r.Close
        Set r = Nothing
    
        CountRanks = RC
    
    End Function
    In the control source of the text box:
    =CountRanks()

  5. #5
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Thank you very much Steve
    I will experiment
    Yes works very well on the report
    Click image for larger version. 

Name:	ghh.JPG 
Views:	12 
Size:	44.4 KB 
ID:	18107

  6. #6
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Thank you very much Steve Steve Steve Steve
    I've been wonderful to work successfully
    sSQL = "SELECT Rank FROM Query1"

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

Similar Threads

  1. DCount Error
    By drewetzel in forum Access
    Replies: 5
    Last Post: 02-13-2014, 06:57 AM
  2. Dcount Error
    By waqas in forum Queries
    Replies: 3
    Last Post: 07-28-2012, 08:24 PM
  3. DCount on a Query giving #Name? error
    By Huddle in forum Access
    Replies: 9
    Last Post: 06-20-2012, 11:40 AM
  4. Replies: 5
    Last Post: 12-15-2011, 11:16 AM
  5. DCount
    By nsteenhaut in forum Queries
    Replies: 2
    Last Post: 10-04-2011, 05:00 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