Results 1 to 4 of 4
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    count record by first 2 caharcter (2000 sr-1)

    I use thisline of code to count record in field ...
    Is possible to count in the same fied only the record with the first 2 ga

  2. #2
    Star Lounger
    Join Date
    Sep 2002
    Location
    Hastings, Sussex, England
    Posts
    67
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: count record by first 2 caharcter (2000 sr-1)

    Hi!

    You need to add a Where clause to your SQL statement

    Set RSD1 = DB1.OpenRecordset("SELECT COUNT(*) FROM ANAGRAFICA1 WHERE ([insert your field name here] LIKE "65*"))

    or you could use SELECT COUNT(*) FROM ANAGRAFICA1 WHERE (Left([insert your field name here],2) = "65"))

    Try it in the query grid first, by creating your totals query with its Count function, then dragging the data field down to the grid and adding the criteria to this field as a 'Where'. If the field is numeric, change the criteria accordingly.

    Don't forget to check for EOF or use NZ() around the recordset result, or the code will fall over.

    Have fun!

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: count record by first 2 caharcter (2000 sr-1)

    Instead of opening a recordset, you can use the DCount function:
    <code>
    Conta_Record1 = DCount("*", "Anagrafica", "[FieldName] Like '65*'")
    </code>
    where FieldName is the name of the field whose first two characters should be "65".

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: count record by first 2 caharcter (2000 sr-1)

    Tks to all!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •