write to text box without focus

  • Thread starter Dsperry101 via AccessMonster.com
  • Start date
D

Dsperry101 via AccessMonster.com

Hey everyone ,

I have a report I'm trying to build based on a table fittings , the
list can vary so I am trying to build the report form the table. I am using a
number of textboxes , positioning and sizing the based on the quanity of
fields in the table.
The problem is in writing the text to the boxes. When I try to modify
the text of the control it says I can't do unless it has focus and when I try
to set focus it says method not supported ( I guess in report mode). How can
I change the text of the text box.

Set rst = db.OpenRecordset("tblFtgs", dbOpenTable)
rst.MoveFirst

For index = 2 To (fittings + 1)
'
' a b c d e
'1 drawer slots a b c d e f g h 8" wide
'2 10" high
'3
'4
'5
'6
'7
'8
'
posstr = rst![fldLocation]
col = Val(Asc(Left(posstr, 1))) - 64
row = Val(Mid(posstr, 2, 1))
pos = Val(Asc(Right(posstr, 1))) - 64
If col = 8 Then col = 7
Debug.Print "row = " & Str(row) & "col = " & Str(col) & "pos = " & Str
(pos)
xpos = 200 + (diagwidth * (col - 1))
ypos = 10 + (diagheight * (row - 1)) + (pos * drawersize)
Report_rptTest.Controls(index).Left = xpos
Report_rptTest.Controls(index).Top = ypos
Report_rptTest.Controls(index).width = 500
Report_rptTest.Controls(index).height = 125
Report_rptTest.Controls(index).Visible = True
Report_rptTest.Controls(index).BackColor = 25000
rst.MoveNext
Next index
db.Close

End Sub

The form has about 200 text boxes and I'm just positioning and using as
many as I need to build the report.

I want to :
Report_rptTest.Controls(index).text = "fitting description"
Any ideas how to do this ??

Thanks ahead of time

Dan S
 
M

Marshall Barton

Dsperry101 said:
I have a report I'm trying to build based on a table fittings , the
list can vary so I am trying to build the report form the table. I am using a
number of textboxes , positioning and sizing the based on the quanity of
fields in the table.
The problem is in writing the text to the boxes. When I try to modify
the text of the control it says I can't do unless it has focus and when I try
to set focus it says method not supported ( I guess in report mode). How can
I change the text of the text box.

Set rst = db.OpenRecordset("tblFtgs", dbOpenTable)
rst.MoveFirst

For index = 2 To (fittings + 1)
'
' a b c d e
'1 drawer slots a b c d e f g h 8" wide
'2 10" high
'3
'4
'5
'6
'7
'8
'
posstr = rst![fldLocation]
col = Val(Asc(Left(posstr, 1))) - 64
row = Val(Mid(posstr, 2, 1))
pos = Val(Asc(Right(posstr, 1))) - 64
If col = 8 Then col = 7
Debug.Print "row = " & Str(row) & "col = " & Str(col) & "pos = " & Str
(pos)
xpos = 200 + (diagwidth * (col - 1))
ypos = 10 + (diagheight * (row - 1)) + (pos * drawersize)
Report_rptTest.Controls(index).Left = xpos
Report_rptTest.Controls(index).Top = ypos
Report_rptTest.Controls(index).width = 500
Report_rptTest.Controls(index).height = 125
Report_rptTest.Controls(index).Visible = True
Report_rptTest.Controls(index).BackColor = 25000
rst.MoveNext
Next index
db.Close

End Sub

The form has about 200 text boxes and I'm just positioning and using as
many as I need to build the report.

I want to :
Report_rptTest.Controls(index).text = "fitting description"
Any ideas how to do this ??


Actually, that's not what you want to do ;-)

First, you almost never use the .Text property in Access, it
is only useful in special situations. Use the .Value
property instead, but since it is the dafault property of
data controls, you do not need to specify it.

OTOH, even if you used the correct property, it wouldn't
work because you can not "push" values into a report.
Reports operate asynchronously, so you can not control the
timing and other processing that's done by a report.

Finally, you should not use the Report_reportname syntax.
It refers to the default instance of the report's class
module and even if it works in many situations, it really
serves a different and rather special purpose.

Instead, you should use the Reports!reportname construct.
If you had used this sybtax, you would have immediately
noticed that the report must be open before you can access
it (even if what you want to do won't work). This is
another, roundabout way, of saying that you can't "push"
values into a report.

You should set things up so the report sets its own
properties/values. For the properties that position the
text boxes, put the code in the report's Open event.
Setting a control's value should be done in the control
section's Format event.

To let the report know what table you want it to use, pass
the its name to the report in the OpenReport method's
OpenArgs argument.
 
O

OldPro

Dsperry101 said:
I have a report I'm trying to build based on a table fittings , the
list can vary so I am trying to build the report form the table. I am using a
number of textboxes , positioning and sizing the based on the quanity of
fields in the table.
The problem is in writing the text to the boxes. When I try to modify
the text of the control it says I can't do unless it has focus and when I try
to set focus it says method not supported ( I guess in report mode). How can
I change the text of the text box.
Set rst = db.OpenRecordset("tblFtgs", dbOpenTable)
rst.MoveFirst
For index = 2 To (fittings + 1)
'
' a b c d e
'1 drawer slots a b c d e f g h 8" wide
'2 10" high
'3
'4
'5
'6
'7
'8
'
posstr = rst![fldLocation]
col = Val(Asc(Left(posstr, 1))) - 64
row = Val(Mid(posstr, 2, 1))
pos = Val(Asc(Right(posstr, 1))) - 64
If col = 8 Then col = 7
Debug.Print "row = " & Str(row) & "col = " & Str(col) & "pos = " & Str
(pos)
xpos = 200 + (diagwidth * (col - 1))
ypos = 10 + (diagheight * (row - 1)) + (pos * drawersize)
Report_rptTest.Controls(index).Left = xpos
Report_rptTest.Controls(index).Top = ypos
Report_rptTest.Controls(index).width = 500
Report_rptTest.Controls(index).height = 125
Report_rptTest.Controls(index).Visible = True
Report_rptTest.Controls(index).BackColor = 25000
rst.MoveNext
Next index
db.Close
The form has about 200 text boxes and I'm just positioning and using as
many as I need to build the report.
I want to :
Report_rptTest.Controls(index).text = "fitting description"
Any ideas how to do this ??

Actually, that's not what you want to do ;-)

First, you almost never use the .Text property in Access, it
is only useful in special situations. Use the .Value
property instead, but since it is the dafault property of
data controls, you do not need to specify it.

OTOH, even if you used the correct property, it wouldn't
work because you can not "push" values into a report.
Reports operate asynchronously, so you can not control the
timing and other processing that's done by a report.

Finally, you should not use the Report_reportname syntax.
It refers to the default instance of the report's class
module and even if it works in many situations, it really
serves a different and rather special purpose.

Instead, you should use the Reports!reportname construct.
If you had used this sybtax, you would have immediately
noticed that the report must be open before you can access
it (even if what you want to do won't work). This is
another, roundabout way, of saying that you can't "push"
values into a report.

You should set things up so the report sets its own
properties/values. For the properties that position the
text boxes, put the code in the report's Open event.
Setting a control's value should be done in the control
section's Format event.

To let the report know what table you want it to use, pass
the its name to the report in the OpenReport method's
OpenArgs argument.

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -

Another trick that works for something like a title or subtitle that
is changeable, is to use a global string variable, and return it in a
function that is called in the open event of the report. The function
can be assigned to the textbox, for example: txtTitle=GetTitle( ).
 

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