0
votes

Im having trouble passing a value from form2 into form1. I want to be able to type a string in text0 of form2. When I click a button on form1, it should fill in the Form1.Text0 with Form2.Text0. I just get a message saying null.

Here's the code

Private Sub Command4_Click()

Dim box1 As Object
Dim feedBox As Object

Set box1 = Forms!Form1!Text0
Set feedBox = Forms!Form2!Text0

MsgBox "Feedbox is " & feedBox.Value


box1 = feedBox.Value

MsgBox "Box1 is " & box1



End Sub
1
aren't controls marked as "private" by default? Perhaps exposing the data as a public variable will get you what you're after... - sous2817
Forms are just glorified classes. Expose a property. That's exactly what I did with this code. I recommend taking a look at it. christopherjmcclellan.wordpress.com/2014/03/08/… - RubberDuck

1 Answers

0
votes

You only need this code.

Private Sub Command4_Click()
    Me.Text0 = Forms!Form2!Text0
End Sub

The Command button will reside on Form1, so the above code is very plainly doing what it needs to do. Just make sure the Form2 is open. No need ot create any objects.