在 VBA 中打开报表时如何为未绑定的文本框赋值?
How do I assign a value to an unbound textbox when opening report in VBA?
我正在使用 Access 2013 并收到一份报告,称我试图在打开时设置八个未绑定文本框的值。在我目前编写的代码中,我打开了一个记录集并用它来计算八项的值。这部分代码工作正常。现在我想将这八个值放入报告中,在计算中使用它们。
报告中第一个未绑定的文本框名称是“CivPistonUnder”
代码如下:
Dim strDocName As String
Dim lngPistonUnder As Long
strDocName = "rptAWMP"
DoCmd.OpenReport strDocName, acViewPreview, , , acWindowNormal
'this is where I want to set the value of the unbound textbox
'I have tried
Me.CivPistonUnder = lngPistonUnder
'I get a compilation error: Method or data member not found
'I tried
Set CivPistonUnder = lngPistonUnder
'I get Compile error: Object required
'I tried
Set Report.rptAWMP!CivPistonUnder = lngPistonUnder
'I get Object Required
有没有办法将此信息传递给报告?
在打印预览中打开报表后,您无法操作报表上的数据。它模拟打印,发送到打印机后您也无法更改任何内容。 :)
您必须在报告事件中执行此操作,例如Report_Load
.
Private Sub Report_Load()
' This will work
Me.txtUnbound.Value = "Hello World!"
End Sub
要将值传递给事件过程,您可以例如使用 TempVars,或 Public 数组/集合。
我正在使用 Access 2013 并收到一份报告,称我试图在打开时设置八个未绑定文本框的值。在我目前编写的代码中,我打开了一个记录集并用它来计算八项的值。这部分代码工作正常。现在我想将这八个值放入报告中,在计算中使用它们。
报告中第一个未绑定的文本框名称是“CivPistonUnder”
代码如下:
Dim strDocName As String
Dim lngPistonUnder As Long
strDocName = "rptAWMP"
DoCmd.OpenReport strDocName, acViewPreview, , , acWindowNormal
'this is where I want to set the value of the unbound textbox
'I have tried
Me.CivPistonUnder = lngPistonUnder
'I get a compilation error: Method or data member not found
'I tried
Set CivPistonUnder = lngPistonUnder
'I get Compile error: Object required
'I tried
Set Report.rptAWMP!CivPistonUnder = lngPistonUnder
'I get Object Required
有没有办法将此信息传递给报告?
在打印预览中打开报表后,您无法操作报表上的数据。它模拟打印,发送到打印机后您也无法更改任何内容。 :)
您必须在报告事件中执行此操作,例如Report_Load
.
Private Sub Report_Load()
' This will work
Me.txtUnbound.Value = "Hello World!"
End Sub
要将值传递给事件过程,您可以例如使用 TempVars,或 Public 数组/集合。