Good Day All,
I am seeking to find a way to sum a field in a query generated in VBA.
Using DSum works well if the query already exist and is simply called in VBA. However when the query is generate in VBA the DSum function does not work. Here is my code to explain my situation:
The DSum("Sales", "[Sales Analysis]") works because the "Sales Analysis" exist.
But the DSum("Sales", "[rst2]") does not work as it is created in this subroutine.
Would be grateful for assistance in explaining my challenge
I am seeking to find a way to sum a field in a query generated in VBA.
Using DSum works well if the query already exist and is simply called in VBA. However when the query is generate in VBA the DSum function does not work. Here is my code to explain my situation:
Code:
Private Sub YearByMonths_Click()
Dim curDatabase As DAO.Database
Dim rst2 As DAO.Recordset
Set curDatabase = CurrentDb
Set rst2 = curDatabase.OpenRecordset("YearMonthSales")
MsgBox DSum("Sales", "[Sales Analysis]")
MsgBox DSum("Sales", "[rst2]")
rst2.Update
Set rst2 = Nothing
Set curDatabase = Nothing
End Sub
The DSum("Sales", "[Sales Analysis]") works because the "Sales Analysis" exist.
But the DSum("Sales", "[rst2]") does not work as it is created in this subroutine.
Would be grateful for assistance in explaining my challenge