ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   userform parameters (https://www.excelbanter.com/excel-programming/360303-userform-parameters.html)

Mike Archer

userform parameters
 
Hello - I have a lot of userforms that use global variables that are created
just for the purpose of populating the userforms. Is there a way to create a
userform that accepts parameters? How? And what would be the syntax to show
the userform ans pass the parameters to it?
--
Thanks,
Mike

K Dales[_2_]

userform parameters
 
You can easily accept parameters for the userform - but how do you want them
entered? In worksheet cells, or in a dialog box? This shows examples of
both, prompting the user for one parameter and taking the second from Cell
A1. The userform needs two textboxes, Textbox1 and Textbox2, for this
example:

Sub TestForm()
Dim Param1 As String

Param1 = InputBox("Enter Parameter 1:")
UserForm1.TextBox1 = Param1
UserForm1.TextBox2 = Range("A1").Value
UserForm1.Show

End Sub

--
- K Dales


"Mike Archer" wrote:

Hello - I have a lot of userforms that use global variables that are created
just for the purpose of populating the userforms. Is there a way to create a
userform that accepts parameters? How? And what would be the syntax to show
the userform ans pass the parameters to it?
--
Thanks,
Mike


NickHK

userform parameters
 
Mike,
You can add customer properties to the userform. e.g.
'Assuming you have textbox called txtTester on this user form.
Public Property Let InitText(argText As String)
txtTester.Text = argText
End Property

Or you can create a class that has a reference to a form
'In the class module
Dim MyForm As UserFormdataInput

Public Propert Let InitText(argText As String)
MyForm.txtTester.Text = argText
End Property

Depends how you wish to reuse the forms that you already have.

NickHK

"Mike Archer" wrote in message
...
Hello - I have a lot of userforms that use global variables that are

created
just for the purpose of populating the userforms. Is there a way to

create a
userform that accepts parameters? How? And what would be the syntax to

show
the userform ans pass the parameters to it?
--
Thanks,
Mike




Bob Phillips[_6_]

userform parameters
 
A userform is just a class module, so it can have properties and methods
exposed to other modules, just like other classes. For example

Private mValue As String

Public Property Let myValue(pValue As String)
mValue = pValue
End Property

Private Sub UserForm_Activate()
TextBox1.Text = mValue
End Sub


and in a code module, use

Load UserForm1
UserForm1.myValue = "Hello"
UserForm1.Show

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Mike Archer" wrote in message
...
Hello - I have a lot of userforms that use global variables that are

created
just for the purpose of populating the userforms. Is there a way to

create a
userform that accepts parameters? How? And what would be the syntax to

show
the userform ans pass the parameters to it?
--
Thanks,
Mike





All times are GMT +1. The time now is 10:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com