0
我有一個父窗體,我點擊一個按鈕,啓動第二個窗體進一步用戶輸入,一旦這些值被輸入,然後我需要返回值的父窗體。我如何從第二種形式返回值到第一種形式?從訪問表單傳遞變量到訪問表單
這是我當前的代碼:
'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
@ June7 - 我如何用Global Variable或TempVars來做這些事情? – IcyPopTarts
我從來沒有把TempVars使用,只讀了。我避免了全局變量,因爲當代碼中斷時它們會失去價值 - 這是發展中的一個真正的麻煩。在模塊頭部聲明全局變量。如果您在表單或報表中執行此變量,則該變量可用於該對象中的所有過程。聲明在一個通用模塊中,並可在db中的任何地方使用。 – June7