assigning value to text box

G

Guest

How do I refer to a txtbox on a report, dynamically, regardless of which
report the user chooses?

I have already read the thread here "assigning value to text box", but one
suggestion to doing this, returned an error, the SetFocus line, at
..txtReportMonthYear, Method or data member not found (Error 461).

My form has a list of possible reports.
When the user selects a report, I capture the actual reportname and use it
to Open the report.

I need to assign a value to a txtbox on that report dynamically.

The suggested code (that errors for me) in the previous thread was:
set a value to its own textbox. And there you'd just use this:
Me.txb_Name1.Value = "12345"

I used:
DoCmd.OpenReport strReport, acViewPreview
Me.txtReportMonthYear.SetFocus
Me.txtReportMonthYear = strReportMonthYear

I have also tried a label and varying the "Me":
Me.lblReportMonthYear
Me.[lblReportMonthYear]

Me. and Me!

I did verify that txtReportMonthYear is the name of the txtbox and I copied
it here for 'proof'. I also placed a lblReportMonth to try a label. It
can't be found either.

Even when I am just in the VBA window and typing in the code, I do get an MS
object dropdown telling me a couple of txt fields and a couple of lbl fields,
but not the ones I placed for the month/year. It's not seeing my field(s),
txt and lbl.
This syntax is correct, I think, but requires the name of the report:
' Reports![rR1-E].Report![txtTimePeriod].SetFocus
' Reports![rR1-E]![txtTimePeriod] = strTimePeriod
 
K

Ken Snell [MVP]

The only way to assign a value to a textbox on a Report is within the report
itself, usually using the Format event of the section that contains the
textbox.
 
G

Guest

Thanks, Ken.
I'll research format event for reports.
Just looking for sample syntax.

michaelm

Ken Snell said:
The only way to assign a value to a textbox on a Report is within the report
itself, usually using the Format event of the section that contains the
textbox.

--

Ken Snell
<MS ACCESS MVP>

Michael Miller said:
How do I refer to a txtbox on a report, dynamically, regardless of which
report the user chooses?

I have already read the thread here "assigning value to text box", but one
suggestion to doing this, returned an error, the SetFocus line, at
.txtReportMonthYear, Method or data member not found (Error 461).

My form has a list of possible reports.
When the user selects a report, I capture the actual reportname and use it
to Open the report.

I need to assign a value to a txtbox on that report dynamically.

The suggested code (that errors for me) in the previous thread was:
set a value to its own textbox. And there you'd just use this:
Me.txb_Name1.Value = "12345"

I used:
DoCmd.OpenReport strReport, acViewPreview
Me.txtReportMonthYear.SetFocus
Me.txtReportMonthYear = strReportMonthYear

I have also tried a label and varying the "Me":
Me.lblReportMonthYear
Me.[lblReportMonthYear]

Me. and Me!

I did verify that txtReportMonthYear is the name of the txtbox and I copied
it here for 'proof'. I also placed a lblReportMonth to try a label. It
can't be found either.

Even when I am just in the VBA window and typing in the code, I do get an MS
object dropdown telling me a couple of txt fields and a couple of lbl fields,
but not the ones I placed for the month/year. It's not seeing my field(s),
txt and lbl.
This syntax is correct, I think, but requires the name of the report:
' Reports![rR1-E].Report![txtTimePeriod].SetFocus
' Reports![rR1-E]![txtTimePeriod] = strTimePeriod
 
K

Ken Snell [MVP]

For example, if the textbox is in the page header of the report:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
Me.txtBoxName.Value = "The Value"
End Sub

Note that this value can be read from a textbox on a form:
Me.txtBoxName.Value = Forms!FormName!ControlName.Value

Or it can be passed by the OpenArgs argument of the DoCmd.OpenReport action
(if you're using ACCESS 2002 or 2003):
Me.txtBoxName.Value = Me.OpenArgs

--

Ken Snell
<MS ACCESS MVP>



Michael Miller said:
Thanks, Ken.
I'll research format event for reports.
Just looking for sample syntax.

michaelm

Ken Snell said:
The only way to assign a value to a textbox on a Report is within the report
itself, usually using the Format event of the section that contains the
textbox.

--

Ken Snell
<MS ACCESS MVP>

How do I refer to a txtbox on a report, dynamically, regardless of which
report the user chooses?

I have already read the thread here "assigning value to text box", but one
suggestion to doing this, returned an error, the SetFocus line, at
.txtReportMonthYear, Method or data member not found (Error 461).

My form has a list of possible reports.
When the user selects a report, I capture the actual reportname and use it
to Open the report.

I need to assign a value to a txtbox on that report dynamically.

The suggested code (that errors for me) in the previous thread was:
set a value to its own textbox. And there you'd just use this:
Me.txb_Name1.Value = "12345"

I used:
DoCmd.OpenReport strReport, acViewPreview
Me.txtReportMonthYear.SetFocus
Me.txtReportMonthYear = strReportMonthYear

I have also tried a label and varying the "Me":
Me.lblReportMonthYear
Me.[lblReportMonthYear]

Me. and Me!

I did verify that txtReportMonthYear is the name of the txtbox and I copied
it here for 'proof'. I also placed a lblReportMonth to try a label. It
can't be found either.

Even when I am just in the VBA window and typing in the code, I do get
an
MS
object dropdown telling me a couple of txt fields and a couple of lbl fields,
but not the ones I placed for the month/year. It's not seeing my field(s),
txt and lbl.
This syntax is correct, I think, but requires the name of the report:
' Reports![rR1-E].Report![txtTimePeriod].SetFocus
' Reports![rR1-E]![txtTimePeriod] = strTimePeriod
 
G

Guest

Ok. Researched Format and OnFormat for reports and do not see a way to pass
in a value from a form.

I thought this was a pretty simple task, putting a string "September 2004",
which I have built from a date that the user enters on a form.
I have the variable assigned on the form and the form calls the report.

Isn't there a way to populate txtboxes on a report, from a form???

I'll keep looking.

Ken Snell said:
The only way to assign a value to a textbox on a Report is within the report
itself, usually using the Format event of the section that contains the
textbox.

--

Ken Snell
<MS ACCESS MVP>

Michael Miller said:
How do I refer to a txtbox on a report, dynamically, regardless of which
report the user chooses?

I have already read the thread here "assigning value to text box", but one
suggestion to doing this, returned an error, the SetFocus line, at
.txtReportMonthYear, Method or data member not found (Error 461).

My form has a list of possible reports.
When the user selects a report, I capture the actual reportname and use it
to Open the report.

I need to assign a value to a txtbox on that report dynamically.

The suggested code (that errors for me) in the previous thread was:
set a value to its own textbox. And there you'd just use this:
Me.txb_Name1.Value = "12345"

I used:
DoCmd.OpenReport strReport, acViewPreview
Me.txtReportMonthYear.SetFocus
Me.txtReportMonthYear = strReportMonthYear

I have also tried a label and varying the "Me":
Me.lblReportMonthYear
Me.[lblReportMonthYear]

Me. and Me!

I did verify that txtReportMonthYear is the name of the txtbox and I copied
it here for 'proof'. I also placed a lblReportMonth to try a label. It
can't be found either.

Even when I am just in the VBA window and typing in the code, I do get an MS
object dropdown telling me a couple of txt fields and a couple of lbl fields,
but not the ones I placed for the month/year. It's not seeing my field(s),
txt and lbl.
This syntax is correct, I think, but requires the name of the report:
' Reports![rR1-E].Report![txtTimePeriod].SetFocus
' Reports![rR1-E]![txtTimePeriod] = strTimePeriod
 
G

Guest

Thanks Ken, I'll try those.

Right now I have a formula =forms!frmFormname.txtReportMonthYear.value in
the report's text box, and while I don't get an error, I am not getting the
text to show in the report.

michaelm

Ken Snell said:
For example, if the textbox is in the page header of the report:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
Me.txtBoxName.Value = "The Value"
End Sub

Note that this value can be read from a textbox on a form:
Me.txtBoxName.Value = Forms!FormName!ControlName.Value

Or it can be passed by the OpenArgs argument of the DoCmd.OpenReport action
(if you're using ACCESS 2002 or 2003):
Me.txtBoxName.Value = Me.OpenArgs

--

Ken Snell
<MS ACCESS MVP>



Michael Miller said:
Thanks, Ken.
I'll research format event for reports.
Just looking for sample syntax.

michaelm

Ken Snell said:
The only way to assign a value to a textbox on a Report is within the report
itself, usually using the Format event of the section that contains the
textbox.

--

Ken Snell
<MS ACCESS MVP>

How do I refer to a txtbox on a report, dynamically, regardless of which
report the user chooses?

I have already read the thread here "assigning value to text box", but one
suggestion to doing this, returned an error, the SetFocus line, at
.txtReportMonthYear, Method or data member not found (Error 461).

My form has a list of possible reports.
When the user selects a report, I capture the actual reportname and use it
to Open the report.

I need to assign a value to a txtbox on that report dynamically.

The suggested code (that errors for me) in the previous thread was:
set a value to its own textbox. And there you'd just use this:
Me.txb_Name1.Value = "12345"

I used:
DoCmd.OpenReport strReport, acViewPreview
Me.txtReportMonthYear.SetFocus
Me.txtReportMonthYear = strReportMonthYear

I have also tried a label and varying the "Me":
Me.lblReportMonthYear
Me.[lblReportMonthYear]

Me. and Me!

I did verify that txtReportMonthYear is the name of the txtbox and I
copied
it here for 'proof'. I also placed a lblReportMonth to try a label. It
can't be found either.

Even when I am just in the VBA window and typing in the code, I do get an
MS
object dropdown telling me a couple of txt fields and a couple of lbl
fields,
but not the ones I placed for the month/year. It's not seeing my
field(s),
txt and lbl.
This syntax is correct, I think, but requires the name of the report:
' Reports![rR1-E].Report![txtTimePeriod].SetFocus
' Reports![rR1-E]![txtTimePeriod] = strTimePeriod
 
G

Guest

Note that this value can be read from a textbox on a form:
Me.txtBoxName.Value = Forms!FormName!ControlName.Value

Yes. This piece (finally) worked.
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
Me.txtReportMonthYear.Value = Forms!
frmSwitchboardReportsExecutiveScorecard!txtReportMonthYear.Value
End Sub
Or it can be passed by the OpenArgs argument of the DoCmd.OpenReport action
(if you're using ACCESS 2002 or 2003):
Me.txtBoxName.Value = Me.OpenArgs

Nope. This does not work:
on form-
DoCmd.OpenReport strReport, acViewPreview, , , , strReportMonthYear '
value is <September 2004>
on report-
text box name (copied here) txtReportMonthYear

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
Me.txtReportMonthYear.Value = Me.OpenArgs
End Sub

Michaelm
 
K

Ken Snell [MVP]

You're close here with your syntax. Just tweak it slightly:

=forms!frmFormname!txtReportMonthYear.value

--

Ken Snell
<MS ACCESS MVP>

Michael Miller said:
Thanks Ken, I'll try those.

Right now I have a formula =forms!frmFormname.txtReportMonthYear.value in
the report's text box, and while I don't get an error, I am not getting the
text to show in the report.

michaelm

Ken Snell said:
For example, if the textbox is in the page header of the report:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
Me.txtBoxName.Value = "The Value"
End Sub

Note that this value can be read from a textbox on a form:
Me.txtBoxName.Value = Forms!FormName!ControlName.Value

Or it can be passed by the OpenArgs argument of the DoCmd.OpenReport action
(if you're using ACCESS 2002 or 2003):
Me.txtBoxName.Value = Me.OpenArgs

--

Ken Snell
<MS ACCESS MVP>



Thanks, Ken.
I'll research format event for reports.
Just looking for sample syntax.

michaelm

:

The only way to assign a value to a textbox on a Report is within
the
report
itself, usually using the Format event of the section that contains the
textbox.

--

Ken Snell
<MS ACCESS MVP>

How do I refer to a txtbox on a report, dynamically, regardless of which
report the user chooses?

I have already read the thread here "assigning value to text box",
but
one
suggestion to doing this, returned an error, the SetFocus line, at
.txtReportMonthYear, Method or data member not found (Error 461).

My form has a list of possible reports.
When the user selects a report, I capture the actual reportname
and
use it
to Open the report.

I need to assign a value to a txtbox on that report dynamically.

The suggested code (that errors for me) in the previous thread was:
set a value to its own textbox. And there you'd just use this:
Me.txb_Name1.Value = "12345"

I used:
DoCmd.OpenReport strReport, acViewPreview
Me.txtReportMonthYear.SetFocus
Me.txtReportMonthYear = strReportMonthYear

I have also tried a label and varying the "Me":
Me.lblReportMonthYear
Me.[lblReportMonthYear]

Me. and Me!

I did verify that txtReportMonthYear is the name of the txtbox and I
copied
it here for 'proof'. I also placed a lblReportMonth to try a
label.
It
can't be found either.

Even when I am just in the VBA window and typing in the code, I do
get
an
MS
object dropdown telling me a couple of txt fields and a couple of lbl
fields,
but not the ones I placed for the month/year. It's not seeing my
field(s),
txt and lbl.
This syntax is correct, I think, but requires the name of the report:
' Reports![rR1-E].Report![txtTimePeriod].SetFocus
' Reports![rR1-E]![txtTimePeriod] = strTimePeriod
 
K

Ken Snell [MVP]

Not sure why the OpenArgs isn't working for you... what you've posted looks
correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top