I’m trying to use this little tid bit of vba code to fill in some textboxes on a report I’m putting together without any kind of luck finding anything on google.
Function GetTotals()
Dim db As DAO.Database
Dim qdef As DAO.QueryDef
Dim rst As DAO.Recordset
10 Set db = DBEngine(0)(0)
20 Set qdef = db.QueryDefs("FoodLogDetails")
30 Set rst = qdef.OpenRecordset(dbOpenDynaset)
40 If rst.RecordCount = 0 Then GoTo Cleanup
50 rst.MoveFirst
60 Do Until rst.EOF
70 Select Case qdef![WhichMeal]
71 Case "Breafast" 'if matched add to the textbox and so on for the others
80 txtBrkCalTot = txtBrkCalTot + TotalCalories 'total calories +
90 Case "AM Snack"
100 Case "Lunch"
110 Case "PM Snack"
120 Case "Dinner"
130 Case "Evening Snack"
140 End Select
150 rst.MoveNext
160 Loop
170 Debug.Print WhichMeal
Cleanup:
180 db.Close
190 qdef.Close
200 rst.Close
210 Set qdef = Nothing
220 Exit Function
End Function
I’ve tried different thing and kept getting different errors. The one I get with the current snip is at line 30, Run time error # 3061 - Too few parameters. Expected 1. I’m using a query for my recordset and the same one the report is bound to. I’ve used this code in other parts of my app and it’s worked fine. But its been used with forms and subforms not reports. I’m thinking that may have something to do with it but not sure. I’ve even tried it like - Set rst = db.OpenRecordset ("FoodLogDetails") - without the querydef parts, with the same error message. If anybody could help I sure would appreciate it Oh! I almst forgot. i'm using access 2013.
Steven