【发布时间】:2017-09-25 00:25:03
【问题描述】:
我有一个父表单,我单击一个按钮启动第二个表单以供用户进一步输入,一旦输入这些值,我需要将值返回到父表单。如何将值从第二种形式返回到第一种形式?
这是我当前的代码:
'Form 1 - Main Form called frmFirstSet
Private Sub cmdDoStep1_Click()
'Declare Variables
Dim OrderNumber As String
'Get the OrderNumber
OrderNumber = Me.[frmDLZC].Form!OrderNumber
'Open the second form for data Capture
DoCmd.OpenForm "frmInputValues", acNormal
'Return variables from frmInputValues
Debug.Print green
Debug.Print red
Debug.Print orange
End Sub
'Form 2 - Secondary Form launched for data capture
Private Sub cmdReturnToStep1_Click()
Dim green As String, red As String, orange As String
'Ensure all values have been input
If IsNull(Me!txtgreen) Then
MsgBox "Please Input the Value for green", vbOKOnly
Me.txtgreen.SetFocus
Exit Sub
Else
green = Me.txtgreen
End If
If IsNull(Me!txtred) Then
MsgBox "Please Input the Value for red", vbOKOnly
Me.txtred.SetFocus
Exit Sub
Else
red = Me.txtred
End If
If IsNull(Me!txtorange) Then
MsgBox "Please Input the Value for orange", vbOKOnly
Me.txtorange.SetFocus
Exit Sub
Else
orange = Me.txtorange
End If
'How to return these variables to the original form
End Sub
【问题讨论】:
-
选项:全局变量、TempVars、form 2 设置 form1 上文本框的值。
-
@June7 - 我将如何使用全局变量或 TempVars 做到这一点?
-
我从未使用过 TempVars,只是阅读了一下。我避免使用全局变量,因为它们在代码中断时会失去价值——这在开发中是一个真正的麻烦。在模块头中声明全局变量。如果您在表单或报表中执行此操作,则该变量可用于该对象中的所有过程。在通用模块中声明并在数据库中的任何位置可用。
标签: ms-access vba ms-access-2013