Hi Steve
Thanks for your reply. I'm familiar with the other methods, I just thought that the Total line was nice to keep on the table - that way I dont need to create a query, report or whatever.
I could add a line with total on it, but I like the way the button makes it 'live' so you can filter out some of the records and it updates.
Hi. Pardon me for jumping in... I seem to recall having a discussion about this before where we concluded it was indeed possible, but I can't seem to find the thread to remind me how we did it. So, I just had to do a little experiment and came up with the following expression instead:Yeah, just curious if it could be done really!
Application.CommandBars.ExecuteMso "RecordsTotals"
Okay, here's how I was able to set the field to have the Sum in the Totals Row.I'm not sure yet how to do the "sum" part.
FieldName.Properties("AggregateType")=0
CurrentDb.TableDefs("YourTableName").Properties("TotalsRow") = True
Sub PopulateTotalsRow()
CurrentDb.TableDefs("table1").Properties("TotalsRow") = True
'number/currency fields
CurrentDb.TableDefs("table1").Fields("Payment1").Properties("AggregateType") = 0 'sum
CurrentDb.TableDefs("table1").Fields("Income1").Properties("AggregateType") = 1 'average
CurrentDb.TableDefs("table1").Fields("Income2").Properties("AggregateType") = 2 'count
CurrentDb.TableDefs("table1").Fields("Field1").Properties("AggregateType") = 3 'maximum
CurrentDb.TableDefs("table1").Fields("Other").Properties("AggregateType") = 4 'minimum
CurrentDb.TableDefs("table1").Fields("NField").Properties("AggregateType") = -1 'none
'text / boolean fields
CurrentDb.TableDefs("table1").Fields("Active").Properties("AggregateType") = 2 'count
End Sub
Happy Easter!Thanks for the replies guys - I'll give this a try.
Hope you enjoy the weekend!
BTW, I've never seen need to use it. My users never get to see tables and any total I'd want is normally on a filtered subset of records, or after grouping. If users want totals, they can have it in an Access report or by my adding =Sum() to a column after the data has been exported to Excel.
Dim prop As DAO.Property
Set prop = CurrentDb.TableDefs("* Table Counts").Fields("Count").CreateProperty("AggregateType", dbInteger, 0)
CurrentDb.TableDefs("* Table Counts").Fields("Count").Properties.Append prop
CurrentDb.TableDefs("* Table Counts").Properties.Append CurrentDb.TableDefs("* Table Counts").CreateProperty("TotalsRow", dbBoolean, True)
CurrentDb.TableDefs("* Table Counts").Fields.Refresh
DoCmd.OpenTable "* Table counts", acViewNormal
CurrentDb.TableDefs("* Table Counts").Properties("TotalsRow") = True
CurrentDb.TableDefs("* Table Counts").Fields("Count").Properties("AggregateType") = 0