excelnut1954 said:
When UserForm4 comes up, the user enters data in TextBox1. When the
user completes UserForm4, he clicks Next, and UserForm6 comes up. I
would like the number entered in TextBox1 of UserForm4 to automatically
populate TextBox7 of UserForm6.
Can this be done?
Thanks,
J.O.
' ------------------------------define this to constant somewhere
public const CancelClicked = 0
public const NextClicked = 1
'----both user form code
Option Explicit
Private m_bResult As Boolean
Property Get Result() As Boolean
Result = m_bResult
End Property
Private Sub btnCancel_Click()
m_bResult = CancelClicked
Hide
End Sub
Private Sub btnNext_click()
If Not ValidateUserInput() Then Exit Sub
m_bResult = NextClicked
Hide
End Sub
Private Function ValidateUserInput() As Boolean
ValidateUserInput = False
'if data don't fit criteria then exit function
ValidateUserInput = True
End Function
' -------------- your module code
load UserForm4
UserForm4.Show
if UserForm4.Result = NextClicked then
load UserForm6
UserForm6.TextBox7.value = userForm4.TextBox1.value
UserForm6.Show
' do something with values from UserForm6
unload userForm6
end if
unload UserForm4
-------------------------
The clue is that data are initiated and processed in parent module not
in user form directly.
Initiated after loading user form , processed after returning from .show
In general user form shouldn't interact with data which is not a part of
user form.
Everything can be done in parent module after hiding user form.
Try to not have unload me in your user form and you'll see that
everything becomes simpler.