Just started with Access VBA today and imagine this is a simple fix. The program calculates total guests in each service category. I must be missing something simple.
Public Sub CalculateTotalGuestsForEachService()
'Declare variables
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim intTotalParty As Integer
'Set the current database
Set db = CurrentDb
'Set the recordset
Set rst = db.OpenRecordset("Select Orders.* From Orders Where ServiceID = 1")
'Cycle through the records
Do While Not rst.EOF
intTotalParty = intTotalParty + rst!NoInParty
rst.MoveNext
Loop
'Display total amount
MsgBox "The total is " & intTotalParty
'Close the recordset
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
NoInPartyNULL in any of the records?NZfunction. But what you should really do isdb.OpenRecordset("Select sum(NoInParty) From Orders Where ServiceID = 1")instead of fetching all those irrelevant columns and rows and slowly adding them one by one on the client.