vba - How to change ControlSource of textbox on sub report? - Stack Overflow

I have an Access form with sub-report on it for preview. This way I have the print, save and email butt

I have an Access form with sub-report on it for preview. This way I have the print, save and email buttons "docked" to the bottom of the form window while scolling the report.

Form_Load includes code to set the subReport.SourceObject property, to show the selected report.

The Report_Load sub includes code to populate the labels' text (taken from a table) according to selected language.

rpt.Controls(rsContorlsTexts(0)).Caption = rsContorlsTexts(1)

Some of the textboxes also have text is inserted from the table, basically replacing the name of the text with it's value. For example: report's txtTitle.ControlSource is set to "="txtTitle " & [Title]" at design and the code replaces "txtTtile" with the text from the table.

with rpt
  .Controls(rsContorlsTexts(0)).ControlSource = Replace(.Controls(rsContorlsTexts(0)).ControlSource, rsContorlsTexts(0), rsContorlsTexts(1))
end with

I'm using textboxes because I need their CanGrow property which labels don't have.

After the code replaces the ControlSource of the first textbox, the code breaks with the error: 267:The expression you entered refers to an object that is closed or does not exist.

The same error raised also with unbounded textbox, so it's not the replace function:

.Controls(rsContorlsTexts(0)).ControlSource = "=""abc "" & [Title]"

Label's captions runs without errors. Same if I open the report directly - no errors.

Any ideas how to solve it before I give up on the docked buttons?

I have an Access form with sub-report on it for preview. This way I have the print, save and email buttons "docked" to the bottom of the form window while scolling the report.

Form_Load includes code to set the subReport.SourceObject property, to show the selected report.

The Report_Load sub includes code to populate the labels' text (taken from a table) according to selected language.

rpt.Controls(rsContorlsTexts(0)).Caption = rsContorlsTexts(1)

Some of the textboxes also have text is inserted from the table, basically replacing the name of the text with it's value. For example: report's txtTitle.ControlSource is set to "="txtTitle " & [Title]" at design and the code replaces "txtTtile" with the text from the table.

with rpt
  .Controls(rsContorlsTexts(0)).ControlSource = Replace(.Controls(rsContorlsTexts(0)).ControlSource, rsContorlsTexts(0), rsContorlsTexts(1))
end with

I'm using textboxes because I need their CanGrow property which labels don't have.

After the code replaces the ControlSource of the first textbox, the code breaks with the error: 267:The expression you entered refers to an object that is closed or does not exist.

The same error raised also with unbounded textbox, so it's not the replace function:

.Controls(rsContorlsTexts(0)).ControlSource = "=""abc "" & [Title]"

Label's captions runs without errors. Same if I open the report directly - no errors.

Any ideas how to solve it before I give up on the docked buttons?

Share Improve this question edited Feb 11 at 12:27 bbProg asked Feb 11 at 12:03 bbProgbbProg 73 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

SO requires enough code to recreate the problem. I can't recreate your issue with what you posted. However, have you tried stepping through the code and when the error occurs you will be able to see which line of code is causing the error? Also, if there is only one text box you're editing, why are you not naming the control and referring directly to it? Something like:

Set db = CurrentDb
Set rec = db.OpenRecordset("Select ReportName from tblReports where Rpt_Number = '" & Me.RptNumber & "'")

If rec.EOF = True Then
Else
    Me.ReportTitle.Text = rec("ReportName")
End If

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745213293a4616970.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信