将变量从一种形式传递到另一种形式 [英] Pass variables from one form to another
问题描述
我试图通过单击按钮将 ComboBox 中的名称从一种形式传递到另一种形式,但我似乎无法让它工作.我不习惯使用 MS Access,我相信这是一个简单的答案.这是我到目前为止所拥有的:
I'm trying to pass the name in a ComboBox from one form to another via button click and I cannot seem to get it to work. I am not accustomed to working with MS Access, and I'm sure its a simple answer. Here's what I have so far:
表格 A:
Private Sub Command104_Click()
On Error GoTo Err_Command104_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Vol_Hrs"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms.Vol_Hours.Search.Value = Me.Combo94.Column(0)
Exit_Command104_Click:
Exit Sub
Err_Command104_Click:
MsgBox Err.Description
Resume Exit_Command104_Click
End Sub
表格 B:
Private Sub cmdAddNew_Click()
On Error GoTo Err_cmdAddNew_Click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.Close
stDocName = "frmLookupScreen"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms.frmLookupScreen.Combo94.Value = Me.Search.Column(0)
Exit_cmdAddNew_Click:
Exit Sub
Err_cmdAddNew_Click:
MsgBox Err.Description
Resume Exit_cmdAddNew_Click
End Sub
推荐答案
当引用一个对象时,即文本框使用这个.
When referencing an object ie text box use this.
Forms!FormName!ObjectName.ObjectProperty = "Testing"
访问方法时使用它.
Forms!FormName.Form.Method.
话虽如此.当我在表单之间使用信息只是为了提取调用表单名称时,我发现它更容易.然后我就可以在那里访问呼叫表上的几乎所有信息.如果需要更新组合框或列表框、更改文本、重新查询等,我还可以将数据推送回调用表单.
Having said that. I find it much easier when I am using information between forms just to pull the calling forms name. Then I have access to almost all of the information on the calling form right there. I can also push data back to the calling form if necessary to update Combo or List boxes, change text, requery and so forth.
Private Sub Form_Load()
Set frmPrevious = Screen.ActiveForm
Me.tbText.value = frmPrevious.cbPassTest.value
End Sub
将该代码放入您正在调用的表单的 LOAD() 中,然后您就可以提取您需要的内容.
Put that code in the LOAD() of the form that you are calling then you can just pull what you need out.
这篇关于将变量从一种形式传递到另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!