0

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

1
  • Can you post the SQL in your query, please? Commented Jul 18, 2014 at 0:04

1 Answer 1

0

My solution was very simple as suggested to me. I just use the Zoom for my text box and pasted in the following:

=round(Sum(IIf([WhichMeal]="Breakfast",[TotalCalories],null)),0) 

whichmeal had to match the selected info "Breakfast" and if so the rounded sum of totalcalories was put in the text box. I did this for 11 more text boxes for different values. I rounded the number to keep them from ballooning beyond the boundaries of my text boxes, and i won't go into details on how that looks, just all kinds of nasty. so there was no need to use vba code. The person who suggested this saved me a lot of warn out fingers and I thank this person very much. Sorry for not adding this to my last post, it's just I was so happy I got it fixed, and at the last minute to, I just plumb wasn't thinkin.

So Yall stay outa trouble

Steven

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.