• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

WHEN REPLACED DSUM WITH TSUM - how to use expression instead of the name of the field

Hi, I have such problem: I have to create an application with MS Access, and I found that using the DSUM function is very slow, in order to make the process of data faster I red about replacing DSUM with other function - you called it TSUM. Anyway the TSUM function uses three parameters ,the first one is the name of the field, but in my case it is not a field,but expression and the function doesn't work.Do you have any idea how this problem can be solved? in my case:
tIZRAZ_FRZ = DLookup("[FRZ]", "ZAPD")
  • 2
1 Solution
TSUM is not a valid Access function, create a recordset instead of the DSUM
    Dim tIZRAZ_FRZ As String 'whatever data type
    Dim tFRZ As Double 'whatever data type
    Dim d As DAO.Database, r As DAO.Recordset, sql As String, rs As DAO.Recordset      
    Set d = CurrentDb
    '... whatever code to get rs!nomer
    Set rs = d.OpenRecordset("whatever sql")    '....then go to whatever record
    tIZRAZ_FRZ = DLookup("[FRZ]", "ZAPD") 'you are missing an argument here, the criteria    
    sql = "select sum(" & tIZRAZ_FRZ & ") as mySUM from zapnew where [nomer] = " & rs!nomer 'whatever
    Set r = d.OpenRecordset(sql)
    If r.EOF Then
        MsgBox "record " & rs!nomer & " does not exist!", vbExclamation
        tFRZ = r!mySum
        MsgBox "value is " & tFRZ
    End If

    Set d = Nothing
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now