Martyh
05-02-2000, 04:41 PM
I've got a problem with reports. This report requires a variable to be passed to it from a form, but I can't seem to pass a variable to the report. I have tried a global
variable but still no luck. I realize there must a way -- but what is it ??
You can pass a variable to a report by setting the value of an unbound text box to the variable using the report's OnOpen property. Example:
[YourReport].OnOpen
Me![YourFieldName] = YourVariable
Danielf
01-09-2001, 11:55 PM
It doesn't work for me :
When I try to use the code :
Me![YourFieldName] = YourVariable
I am receiving the error message : You can't
assign a value to this object.
RpbertS
01-12-2001, 11:29 AM
if you trying to pass the variable from a form to meet a fields criteria on a report try this:
in the criteria section in design view of the report put
[Forms]![formname]![fieldname]
if the field is on a subform simply do this
[Forms]![formname]![subformname]![fieldname]
let me know if this doesnt work
ShardaSuresh
02-07-2001, 10:23 AM
Try This:
me.[myTextBox].caption = globalvariables.variablename
Hope this solves your problem
ListO
02-18-2001, 01:44 PM
Sharda:
I found that your solution worked only if I used a LABEL instead of a TEXTBOX, since the textbox has no caption attribute. I got this sort of thing to work for me using:
me.[myLabel].caption = MyPublicVariable
or
me.[myLabel].caption = [Forms]![formname]![fieldname]
Good luck.
Mike Gurman
02-19-2001, 01:42 AM
That's right actually, for a text box it's:
Me.[myTextBox].Value = YourVariable
Although the .Value part is superfluous, you can just use:
Me.[myTextBox] = YourVariable
If you're getting the error "can't assign a value to this object", then it probably indicates that the object isn't a text box.
HTH
Mike
[This message has been edited by Mike Gurman (edited 02-19-2001).]
Mike Gurman
02-19-2001, 06:14 AM
I've just also re-read the thread here and realised that to use:
Me.anything from the OnOpen event of a report, the text box would need to be on the report (that's what the 'Me' means) - I don't think that will work.
I tend to use the other approach and put the variable into an unbound text box on the form from the OnClick event of a 'print report' button and then reference the form's text box from the report's record source query.
My (in)famous custom email demo uses this approach, if you'd like a copy so you can see it in practice, mail me with 'email demo' in the subject line and I'll send it by reply.
Mike
[This message has been edited by Mike Gurman (edited 02-19-2001).]
Has anyone solved this yet? I'm having problems galore with a report. Because I want to run the report in collumns as opposed to rows, on Report_Open I open a recordset and run through the records assigning the relevant values to the textboxes. Everything works appart from the assigning the recordset values to the preplaced textboxes. I get a run time error 2248 'You can't assign a value to this object'.
This works:
Me.Label9.Caption = rec("Duty_Date").Value
This doesn't:
Me.TestBox.Value = rec("Duty_Date").Value
Let alone this:
Me.TestBox.Value = "Hello"
I'm pulling my hair out. Please help.
Okay since to get a text box to fill with "Hello" you would use the on format event of the detail section I assume that's where your code should go.
Me.TestBox="Hello"
Brilliant. It works. Thanks a million.
J-F