Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding a value to report text field

1 view
Skip to first unread message

Stever

unread,
Jul 7, 2004, 6:11:06 PM7/7/04
to
I have a button that opens a report (SubmittalReport). The record set that
the report is based on does not include one piece of information that I
would like included in the report. I would like to pass a value to a field
called MainFolderName. Below is what I have tried. I don't get any errors
but the information never shows up in the field.


DoCmd.OpenReport stDocName, acViewPreview, , stWhere
Reports!SubmittalReport!MainFolderName = me.stFolderName
DoCmd.RepaintObject acReport, "SubmittalReport"


Thanks in advance for any suggestions you may have.

Steve


fredg

unread,
Jul 7, 2004, 8:24:22 PM7/7/04
to

If you are using Access 2000 or newer, you can pass the value in the
OpenArgs argument:

DoCmd.OpenReport stDocName, acViewPreview, , stWhere, ,
Me!stFolderName

Then in the Report Header Format event:
[MainFolderName] = Me.OpenArgs

If the form is going to remain open when the report is run, you could
also simply refer to the form control in the control source of an
unbound countrol:
=forms!FormName!stFolderName
in which case no additional coding is necessary. Just open the report.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.

Pat Hartman

unread,
Jul 8, 2004, 1:02:20 PM7/8/04
to
Your existing code wasn't working because you cannot
assign a value to report/form fields when the report/form
is not open. Either of fredg's suggestions will be fine.

>.
>

Stever

unread,
Jul 8, 2004, 1:57:13 PM7/8/04
to
Is there a way to pass more than 1 variable using the openargs? I guess I
should have elaborated a bit. I am actually trying to use 2 VBA variables
that exist in the button code that opens the report. One variable fills in
the MainFolder field in the report and the other fills in the SubFolder
field in the report. The code that you supplied works great for a single
variable but is it possible to do the same for multiple variables?

Thanks

Steve

"fredg" <fgut...@example.invalid> wrote in message
news:zbow7eah6m06.s...@40tude.net...

fredg

unread,
Jul 8, 2004, 5:14:09 PM7/8/04
to

It just requires a bit more work.
Concatenate the c0ontrol values in the open arguments using a comma as
delimiter:

DoCmd.OpenReport stDocName, acViewPreview, , stWhere, ,

Me!stFolderName & "," & Me!SubFolderName

Then in the Report's Report Header Format event:

Dim strString1 as String
Dim strString2 as string

strString1 = left(Me.OpenArgs,InStr(Me.OpenArgs,",")-1)
strString2 = Mid(Me.OpenArgs,InStr(Me.OpenArgs,",")+1)
[MainFolderName] =strString1
[SubFolderName] = strString2

Stever

unread,
Jul 8, 2004, 5:44:45 PM7/8/04
to
That was easy! I have sooo much to learn, but with help from people in the
know like you I'll get there!

Thanks again.
Steve

"fredg" <fgut...@example.invalid> wrote in message

news:snjwm1nzshf2.1i...@40tude.net...

James

unread,
Sep 6, 2004, 4:15:07 PM9/6/04
to
I am running Access 2000 and it doesn't seem to be working. I get a compile
error of "Wrong number of arguments or invalid property assignment".

Any ideas?

Ken Snell [MVP]

unread,
Sep 6, 2004, 5:27:53 PM9/6/04
to
OpenArgs is available for reports only in ACCESS 2002 and 2003. It's not
available in 2000.

Put a hidden textbox on your form. Name it txtstFolderName. In your code,
just before you open the report, write the value of the stFolderName
variable into that textbox. Then use the Open event of the report to read
that value from this textbox on your form.

--

Ken Snell
<MS ACCESS MVP>

"James" <Ja...@discussions.microsoft.com> wrote in message
news:A128F380-B30D-4BE9...@microsoft.com...

James

unread,
Sep 6, 2004, 6:13:04 PM9/6/04
to
After I posted, I researched this some more.

You are correct that OpenArgs for Reports is not available in Access 2000.

However, Global Variables are.

I don't like having a report reference a specific form because it eliminates
reusability. I think having the form set a global variable and then having
that report look for that variable (and if it is blank, setting it's own
values) ends up being a much better way of doing things.

Anyway, just my .02.

Ken Snell [MVP]

unread,
Sep 6, 2004, 7:15:03 PM9/6/04
to
Global variables can be used, but suffer from an ignominous "termination" if
an error occurs during the code and you don't have error handlers handling
the error. ACCESS, in this situation, resets global variables back to
default conditions, and you then lose the value and the report will not show
the correct result. That is why I use textboxes on forms for such values,
because they are not affected by this result.

--

Ken Snell
<MS ACCESS MVP>

"James" <Ja...@discussions.microsoft.com> wrote in message

news:3F35B9BC-0ECC-4EE7...@microsoft.com...

0 new messages