Running a module from within a UserForm

  • Thread starter Patrick C. Simonds
  • Start date
P

Patrick C. Simonds

From within UserForm2 when I click on OptionButton1 I want the MakeVisable
code (shown below) to run. The problem is that I get an "object required"
error. What do I need to add?

Private Sub OptionButton1_Click()

Call MakeVisable.MakeVisable

End Sub



Sub MakeVisable()

Label8.Visible = True
Label9.Visible = True

TextBox3.Visible = True
TextBox4.Visible = True

TextBox3.Value = Format$(Now(), "HH:MM")
TextBox4.Value = Format$(Now(), "mm/dd/yy")


End Sub
 
T

Tom Hutchins

Your module doesn't know where the controls it's supposed to change are
located. You can put your MakeVisable sub in the code sheet for the userform:

Private Sub OptionButton1_Click()
Call MakeVisable
End Sub

Sub MakeVisable()
Me.Label8.Visible = True
Me.Label9.Visible = True
Me.TextBox3.Visible = True
Me.TextBox4.Visible = True
Me.TextBox3.Value = Format$(Now(), "HH:MM")
Me.TextBox4.Value = Format$(Now(), "mm/dd/yy")
End Sub

Or, you can leave it in the MakeVisable VBA module if you make modifications
like the following:

'(in the userform code sheet)
Private Sub OptionButton1_Click()
Call MakeVisable.MakeVisable(Me)
End Sub

'(in the MakeVisable module)
Sub MakeVisable(MyForm As UserForm)
MyForm.Label8.Visible = True
MyForm.Label9.Visible = True
MyForm.TextBox3.Visible = True
MyForm.TextBox4.Visible = True
MyForm.TextBox3.Value = Format$(Now(), "HH:MM")
MyForm.TextBox4.Value = Format$(Now(), "mm/dd/yy")
End Sub

Hope this helps,

Hutch
 
P

Patrick C. Simonds

Thank you sir, that was exactly what I needed. I opted for option 1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top