How to retrieve record value from Recordset ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Loras
    New Member
    • Dec 2006
    • 1

    #1

    How to retrieve record value from Recordset ?

    Hello all,
    I'm a newbie in Access vba, so please help...
    I have some vba code to count records, but i also need retrieve value from query SELECT SUM (......). There will be only one record (Total SUM)
    and cannot find how I can do it..

    Here is my vba to count records (maybe it should look similarly..) :

    SQLStmt = "SELECT * FROM TEMP_backup;"
    Set db = CurrentDb
    Set rs = db.OpenRecordse t(SQLStmt)
    If Not rs.EOF Then
    rs.MoveLast
    strOrder = rs.RecordCount ' (place records quantity in "strOrder")
    End If

    Thanks.
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by Loras
    Hello all,
    I'm a newbie in Access vba, so please help...
    I have some vba code to count records, but i also need retrieve value from query SELECT SUM (......). There will be only one record (Total SUM)
    and cannot find how I can do it..

    Here is my vba to count records (maybe it should look similarly..) :

    SQLStmt = "SELECT * FROM TEMP_backup;"
    Set db = CurrentDb
    Set rs = db.OpenRecordse t(SQLStmt)
    If Not rs.EOF Then
    rs.MoveLast
    strOrder = rs.RecordCount ' (place records quantity in "strOrder")
    End If

    Thanks.
    I don't understand where or what your query SELECT SUM (......) is so I need more information.

    Mary

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Try instead :
      Code:
      strOrder = Format(DCount("*","TEMP_backup"),"Standard")
      Format is your choice but I noticed that the value was returned to a string variable.
      This code replaces all of your other code.

      Comment

      Working...