Adding a value to report text field

  • Thread starter Thread starter Stever
  • Start date Start date
S

Stever

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
 
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

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.
 
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.
 
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 said:
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

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.
 
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 said:
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

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.

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
 
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 said:
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 said:
On Wed, 7 Jul 2004 16:11:06 -0600, Stever wrote:

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

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.

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
 
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?

fredg said:
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

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.
 
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 said:
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?

fredg said:
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

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.
 
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 said:
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 said:
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?

fredg said:
On Wed, 7 Jul 2004 16:11:06 -0600, Stever wrote:

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

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.
 
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 said:
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 said:
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 said:
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?

:

On Wed, 7 Jul 2004 16:11:06 -0600, Stever wrote:

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

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.
 
Back
Top