Results 1 to 8 of 8
  1. #1
    clebergyn is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2012
    Location
    Brazil
    Posts
    48

    What is missed in this 'Dcount'? please

    DCount("[codigo]", "locaçao", "[codigo]= "& forms![painel]![codigo] & " And [dtLocação] <= #" & Date & "# And [DtFim] >= #" & Date & "#")



    What is missed in this 'Dcount'? how to do a 'dcount' so using the date "date ()" ? can I use the carctere ">="? please

    I already used a variable d1="*" & date () &"*", and also it did not give right, when it compiles, the dates do not produce / look the certain result

    this 'dcount' above, when he does not give mistake, does not he look for the correct date, because? is it because of the character '>'?
    how to do?

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    The only thing I can think of is that your system date format is not mm/dd/yyyy. MS Access insists on this format in things like DCount and other comparisons. Try changing Date to Format(date,"mm/dd/yyyy"):

    DCount("[codigo]", "locaçao", "[codigo]= "& forms![painel]![codigo] & " And [dtLocação] <= #" & Format(date,"mm/dd/yyyy") & "# And [DtFim] >= #" & Format(date,"mm/dd/yyyy") & "#")

    to for the date to the format MS Access expects. Beyond that, I don't see anything wrong with the DCount.

    HTH

    John

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I agree with John -- there doesn't appear to anything in error syntax-wise.

    Here is a sample Dcount with a date variable from M$oft
    Code:
    Public Function OrdersCount(ByVal strCountry As String, _  
                                          ByVal dteShipDate As Date) As Integer      
      OrdersCount = DCount("[ShippedDate]", "Orders", _    
                           "[ShipCountry] = '" & strCountry & _    
                          "' AND [ShippedDate] > #" & dteShipDate & "#")
     End Function 

  4. #4
    clebergyn is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2012
    Location
    Brazil
    Posts
    48
    it would like that you were trying his examples, since it does not give right the result, I do not know if it is because of the date ' date () ' or because of the characters '>' or '<', I tried for 'betwen', I cannot do them to myself, briefly, it did not give right. if someone knows, and to test, being correct, I would thank

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  6. #6
    clebergyn is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2012
    Location
    Brazil
    Posts
    48
    I sent in annexe
    Attached Files Attached Files

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Code:
    Sub testDCount()
    Dim intx As Integer
    intx = DCount("*", "locaçao", " [dtLocação] <= Date()  And   Date() <=  [dtfim] ")
    End Sub
    I created this routine (subProcedure) to test some of the values and attempts you have in
    your module.

    Code:
    Function c1()
    
    'd1 = "'#'" & Date & "'#'"
    'MsgBox d1
    'c1 = DCount("[codigo]", "locaçao", "[dtLocação] <= " & d1 & " And [DtFim] >= " & d1)
    'c1 = DCount("[codigo]", "locaçao", "Format([dtLocação],'dd/mm/yyyy') <= #" & Format(Now, "mm/dd/yyyy") & "# And format([DtFim],'dd/mm/yyyy') >= #" & Format(Now, "mm/dd/yyyy") & "#")
    'c1 = DCount("[codigo]", "locaçao", "[dtLocação] <= #" & Format(Now, "dd/mm/yyyy") & "# And format([DtFim],'dd/mm/yyyy') >= #" & Format(Now, "mm/dd/yyyy") & "#")
    c1 = DCount("[dtlocação]", "locaçao", "#" & Date & "# Between format([dtLocação],'dd/mm/yyyy') And format([dtfim],'dd/mm/yyyy')")
    
    'between
    
    End Function

  8. #8
    clebergyn is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Dec 2012
    Location
    Brazil
    Posts
    48
    Hello, this routine was correct, very much thank you!
    these collected functions are very complicated with "date"

    Dim intx As Integer
    intx = DCount("*", "locaçao", " [dtLocação] <= Date() And Date() <= [dtfim] ")
    End Subtanks very much

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

Similar Threads

  1. DCount
    By Ray67 in forum Queries
    Replies: 2
    Last Post: 06-26-2012, 10:48 AM
  2. DCount and If
    By Madmax in forum Access
    Replies: 3
    Last Post: 07-28-2011, 06:53 AM
  3. DCount and SQL
    By DSTR3 in forum Queries
    Replies: 3
    Last Post: 12-06-2010, 03:07 PM
  4. Help with Dcount
    By tozey in forum Programming
    Replies: 1
    Last Post: 08-10-2010, 10:53 AM
  5. Warning Message for Missed Date
    By maintt in forum Access
    Replies: 2
    Last Post: 07-23-2010, 09:05 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