View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default What does the Userform.Tag do?

I've seen some code where it's used as (essentially) a variable to pass
information back to the routine that loaded and showed the userform.

For instance, I created a userform with two commandbuttons and a single
checkbox.

This was the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()
Me.Tag = "cancel"
Me.Hide
End Sub
Private Sub CommandButton2_Click()
Me.Tag = "ok"
Me.Hide
End Sub
Private Sub UserForm_Initialize()
Me.CommandButton1.Caption = "Cancel"
Me.CommandButton2.Caption = "ok"
End Sub

Then I loaded the userform (and read the results) in this code in a General
module:

Option Explicit
Sub testme()

Dim UF1 As UserForm1

'load the userform
Set UF1 = New UserForm1

UF1.Show

If UF1.Tag = "ok" Then
MsgBox UF1.CheckBox1.Value
Else
MsgBox "User hit cancel, don't trust the checkbox!"
End If

Unload UF1

End Sub

But you could use it to pass any other info to the userform, too--maybe a string
that initializes a textbox????


Brad E. wrote:

I am curious what the Tag part of a Userform is for?
--
Thanks, Brad E.


--

Dave Peterson