Troubles with TextBox TextProperty

  • Thread starter Thread starter CristianTCDM
  • Start date Start date
C

CristianTCDM

Hello,

I want to display a certain text in an unbound TextBox on a Report and I use
an EventProcedure like this :
Private Sub Report_Open(Cancel As Integer)
Text0.SetFocus
Text0.Text = "HelloWorld"
End Sub
It seems that something is wrong because when I try to open the report it
appears the message : "Run-time error 2101 - The setting you entered isn't
valid for this property"
If somebody can help it will be very appreciated

Thanks
 
Suggestions:

1. Assign the value rather than the text:
Me.Text0 = "HelloWorld"
There's no need to SetFocus.

2. Report_Open is too early.
Use the Format event of the Report Header section, or of the section
containing Text0.

Alternatively, change the control to a label instead of a text box, and
assign its Caption:
Me.Label0.Caption = "HelloWorld"
 
Allen thanks

Your suggestions are very appreciated and I actually manage to introduce a
simple string like "HelloWorld" in a text box using code (not with format
event but with double click of detail section)
In fact I want to introduce a value from a recordset into a textbox (for
printing) and I used GetRows method :
Dim dbs As DAO.Database
Dim rstReteta As DAO.Recordset
Dim varInst As Variant
Dim instROW As Integer
Dim instCOL As Integer
Set dbs = CurrentDb
Set rstReteta = dbs.OpenRecordset("RpInstant")
varInst = rstReteta.GetRows(7)
instROW = UBound(varInst, 2) + 1
instCOL = UBound(varInst, 2) + 1
Me.Text62 = varInst(3, 0)
Set rstReteta = Nothing
Set dbs = Nothing
I tried to run it as a FormatEvent procedure in detail section but the error
message is now "You cant assign a value to this object"
If you have any suggestions please tell me .

Thank you very much
 
You kinda lost me there.

AFAIK, text boxes don't have rows, so I'm not sure how you plan to use
GetRows.

Similarly, reports don't have a DblClick for their Detail section. Well,
actually they do if you are talking about Report view in Access 2007, but
not Print Preview and not in earlier versions, so the idea may not work as
you expect.

Not sure why you could not assign a value in teh Format event procedure of
teh detail section. Perhaps it's already a bound control, or perhaps it was
the GetRows that stymied you.
 
Actually I was trying to get a text from a recordset (using GetRows) and to
display that on a textbox on report and then print . If I use a simple string
, eg Me.Text62="HellowWorld" it works(not with format but with dbl click , as
a test - access2007) , but when I use Me.Text62=varInst(3,0) the mesage is
"You cant assign a value to this object" and I don't know what I have to do
now .
If you don't have any ideas probably I'll try anothr route .

Thank you very much . Your contribution is very appreciated .
 
Okay, so you are using Access 2007, you are in Report view, you don't care
that this does not work in Print Preview, the text box is unbound, and you
are using GetRows to load an array from a recordset and then assign a value
to the unbound text box.

Just tested that, and it does work. Not sure why you have this error.
Although you tested UBound, you didn't test that anything was actually
returned from the recordset. The GetRows method does not load any rows if no
records are returned.

It does strike me that this is not the most efficient approach here. Loading
several rows and columns into a recordset, and then assigning all of them
into an array may not be the best use of memory. It might be more efficient
to include RpInstant in the report's RecordSource, or to use a subquery to
select the desired record, or to use DLookup() to get a single field/row
value. (Or perhaps what you posted is just a simplified version of what you
are actually doing.)
 
Allen thank you very much !

I didn't know about DLookup() function but at your suggestion I studied it
an I find it an easier way to retrieve data from a table than GetRows method
; actually I tested it in my application and everything is just fine .
Thanks again for your time ; I appreciate very much your expertise .
 
Back
Top