Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent! Object reference problem?

Status
Not open for further replies.

mdmarney

IS-IT--Management
Jan 16, 2003
68
0
0
US
I know I have posted this before, but am having trouble getting a good answer.
Here is the current code:
It works great in a form, but not in a report.

Dim rs As Object
Set rs = CurrentDb.OpenRecordset("Select * from tbl_Attendants Where Tee_Shirt_Size = 'L'")
rs.MoveLast
Me.tx_L_Count = rs.RecordCount

**The error is on the assignment to the text box line.**
It says, "You can't assign a value to this object."

Me!tx... Does nott help anything.
Thanks!
*************
M. MARNEY
 
Hi,
Are you simply trying to count the number of "L" tshirts? In this case, you don't need to do it this way. There is a much simpler way using the DCount function.

Here are the steps to follow:
1) Add a text box to the report (we can call it txtShirtCount). It doesn't even have to be visible.
2) The control source for this text box would be:
=DCount("[Tee_Shirt_Size]","tbl_Attendants", "[Tee_Shirt_Size] = 'L'") HTH, [pc2]
Randy Smith
California Teachers Association
 
mdmarney:

Try: Me!tx_L_Count.Value = rs.RecordCount

Hope this helps,

Vic
 
Hi!

One more question (we are a curious bunch!), where is the code you posted?

Jeff Bridgham
bridgham@purdue.edu
 
Randy,
Thank you for the code.
I need to add another field to the where clause though.
Basically...
"[Tee_Shirt_Size] = 'L' AND [Group_ID] = '&[Current_Group_ID]'"
Will this work? *************
M. MARNEY
 
Tried what i had above, but got error. I think I am probably referencing the Current_Group_ID wrong. Any thoughts? *************
M. MARNEY
 
Almost got it!!!!

This is what you are showing me:
"[Tee_Shirt_Size] = 'L' AND [Group_ID] = '&[Current_Group_ID]'"

And this is what the final is supposed to be (presuming that Group_ID is string datatype):
=DCount("[Tee_Shirt_Size]", "tbl_Attendants", "[Tee_Shirt_Size] = 'L'" AND [Group_ID] = '" & [Current_Group_ID] & "'")

STRINGS MUST HAVE SINGLE QUOTE MARKS SURROUNDING THEM. IF NUMERIC, then no quote marks. Here is a sample if the Group_ID is numeric:
=DCount("[Tee_Shirt_Size]", "tbl_Attendants", "[Tee_Shirt_Size] = 'L'" AND [Group_ID] = [Current_Group_ID]") HTH, [pc2]
Randy Smith
California Teachers Association
 
Randy,
Ok, re-read your post and say the answer to my last. Sorry. The code you provided was invalid. I assumed the double-quote after L' was misplaced.
Still having trouble though...

=DCount("[Tee_Shirt_Size]","tbl_Attendants","[Tee_Shirt_Size] = 'L' AND [Parish_Group_ID] = [Parish_Group_ID]")
This code returns the value as if Parish_Group_ID was disregarded.
??? *************
M. MARNEY
 
HI,
This should work:

=DCount("[Tee_Shirt_Size]", "tbl_Attendants", "[Tee_Shirt_Size] = 'L'" AND [Group_ID] = " & [Current_Group_ID]) HTH, [pc2]
Randy Smith
California Teachers Association
 
Did not work. Syntax error - Missing Operand!
One thing that might be causing problems: My actual code reads:
=DCount("[Tee_Shirt_Size]", "tbl_Attendants", "[Tee_Shirt_Size] = 'L'" AND [Parish_Group_ID] = " & [Parish_Group_ID])

How does it know that I want the Parish_Group_ID that corresponds to the current page of the report? *************
M. MARNEY
 
Try

=DCount("[Tee_Shirt_Size]", "tbl_Attendants", "[Tee_Shirt_Size] = 'L' AND [Parish_Group_ID] = " & [Parish_Group_ID])
 
By the way, mdmarney,

Your original code will probably work if you put it in the right print event (for the report detail section: Detail_Print, etc.)
Just try it.

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top