I have two forms. form1 has textbox1 and textbox2 asking user input. It also has a button that the user clicks after filling the boxes. The button closes form1 and opens form2. form2 has textbox3 with has a simple formula adding the values inserted by the use in textbox1 and textbox2. This needs to work even after form1 is closed. How to do this? I gather that there are two possible solutions, but I can't make them work.
Solution 1 is with Global Variables, with code below.
Code:
In a VBA Module:
Option Compare Database
Global Var1 As Single
Global Var2 As Single
In form1 button:
Private Sub Continue_button_Click()
Var1 = Val(Me.textbox1 & "")
Var2 = Val(Me.textbox2 & "")
DoCmd.OpenForm "form2"
DoCmd.Close acForm, Me.Name
End Sub
In form2 textbox3:
=[Var1]+[Var2]
In form2 textbox3 I get the #Name? error
Solution 2 is OpenArgs, with code below
Code:
In the form1 button
Private Sub Continue_button_Click()
docmd.openform "form2",,,,,textbox1 & ":" & textbox2
doCmd.Close acForm, Me.Name
End Sub
In the form2 load event
Var1=split(openargs,":")(0)
Var2=split(openargs,":")(1)
and in form2 textbox3
=[Var1]+[Var2]
This gives me a Run-time error 13 Type mismatch error
In both solutions, there is something line of code that is wrong or some code missing, but I can't figure out what. Any clues?