J,
Here's an example, which I developed from the book I already mentioned.
You need a UserForm1 with the following code. You'll have to name the two
CommandButtons as shown:
Private Sub UserForm_Activate()
Call initialize_controls(data_in)
End Sub
Property Let data_on_form(passed_data As String)
data_in = passed_data
End Property
Property Get data_on_form() As String
data_in = TextBox1.Value
data_on_form = data_in
End Property
Sub initialize_controls(data_in As String)
TextBox1.Value = data_in
End Sub
Private Sub OKButton_Click()
'for Closed with OK button property
OK_clicked = True
Me.Hide
End Sub
Property Get closed_with_OK()
'this property tells a calling procedure whether the OK button was clicked
closed_with_OK = OK_clicked
End Property
Private Sub CancelButton_Click()
Me.Hide
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'if closed with x it calls the Cancel routine,
'so form is hidden, not unloaded
If CloseMode = vbFormControlMenu Then Cancel = True
Call CancelButton_Click
End Sub
Then in a regular module paste this code.
Sub pass_to_uform()
Dim uform_instance As UserForm1
Dim data_to_pass As String
data_to_pass = "widget A"
Set uform_instance = UserForm1
'pass the events from the registry to the form
uform_instance.data_on_form = data_to_pass
uform_instance.Show
'only do if the user chose OK
If uform_instance.closed_with_OK Then
'fill the form events array, with those from the form
data_to_pass = uform_instance.data_on_form
End If
Unload uform_instance
MsgBox data_to_pass
End Sub
Run the code. You'll see the original value "Widget A" in the TextBox.
Change the value and click OK. The form closes and the MsgBox displays your
changed value. Again, all from PED.
hth,