<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Getting Data from a Userform</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Wed, 08 Feb 2012 23:58:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Doug G</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-15849</link>
		<dc:creator>Doug G</dc:creator>
		<pubDate>Sat, 03 Sep 2005 18:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-15849</guid>
		<description>&lt;p&gt;I&#039;m sorry, but I found my error. I did not have frmA1 declared. When I add this declaration (i.e., Dim frmA1 as UserForm1), it works fine.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;m sorry, but I found my error. I did not have frmA1 declared. When I add this declaration (i.e., Dim frmA1 as UserForm1), it works fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug G</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-15848</link>
		<dc:creator>Doug G</dc:creator>
		<pubDate>Sat, 03 Sep 2005 17:44:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-15848</guid>
		<description>&lt;p&gt;Dick mentioned:&lt;/p&gt;
&lt;p&gt;ufForm1 can also be passed to called procedures, so you don&#039;t need to keep everything in one sub.&lt;/p&gt;
&lt;p&gt;However, when I try to pass the userform to a procedure, I get a type mismatch error. What am I doing incorrectly here:&lt;/p&gt;
&lt;p&gt;Set frmA1 = New UserForm1&lt;br&gt;
frmA1.Show&lt;/p&gt;
&lt;p&gt;If frmA1.OK Then&lt;br&gt;
    Read_Settings frmA1&lt;br&gt;
End If&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Dick mentioned:</p>
<p>ufForm1 can also be passed to called procedures, so you don&#8217;t need to keep everything in one sub.</p>
<p>However, when I try to pass the userform to a procedure, I get a type mismatch error. What am I doing incorrectly here:</p>
<p>Set frmA1 = New UserForm1<br />
frmA1.Show</p>
<p>If frmA1.OK Then<br />
    Read_Settings frmA1<br />
End If</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Billkamm</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12688</link>
		<dc:creator>Billkamm</dc:creator>
		<pubDate>Thu, 26 May 2005 14:21:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12688</guid>
		<description>&lt;p&gt;#10&lt;/p&gt;
&lt;p&gt;I loop through all the controls on the form to save/load defaults.  The form also has a multi-page where each page is a department.  When you call that department macro I need to pass the values of the controls to the primary procedure used to control all the macros for that department.&lt;/p&gt;
&lt;p&gt;I want to make it so new modules can be inserted and all the user has to do is link up the values of the controls they created on a new page to their macro.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>#10</p>
<p>I loop through all the controls on the form to save/load defaults.  The form also has a multi-page where each page is a department.  When you call that department macro I need to pass the values of the controls to the primary procedure used to control all the macros for that department.</p>
<p>I want to make it so new modules can be inserted and all the user has to do is link up the values of the controls they created on a new page to their macro.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan De Schutter</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12686</link>
		<dc:creator>Johan De Schutter</dc:creator>
		<pubDate>Thu, 26 May 2005 11:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12686</guid>
		<description>&lt;p&gt;To Billkamm&lt;/p&gt;
&lt;p&gt;Do you want an userform which contains dynamically created checkboxes (or other controls).&lt;br&gt;
The number of checkboxes and the names and values of these checkboxes is based on the number of values and the names and values of a two-dimensional array?&lt;/p&gt;
&lt;p&gt;And the end you want to return an array with contains the names and values selected by the user?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>To Billkamm</p>
<p>Do you want an userform which contains dynamically created checkboxes (or other controls).<br />
The number of checkboxes and the names and values of these checkboxes is based on the number of values and the names and values of a two-dimensional array?</p>
<p>And the end you want to return an array with contains the names and values selected by the user?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Billkamm</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12492</link>
		<dc:creator>Billkamm</dc:creator>
		<pubDate>Wed, 25 May 2005 15:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12492</guid>
		<description>&lt;p&gt;Maybe I&#039;m still missing something here.  If I have a form and I want to get the values off the controls on that form into a standard module procedure.&lt;/p&gt;
&lt;p&gt;No matter what if I add, delete, or change a control on the form I&#039;m going to have to manually update code somewhere. &lt;/p&gt;
&lt;p&gt;Right now I have a &quot;shell&quot; where users in my department can insert their own module and own user form.   Then I have a procedure as part of my shell that will pass a two-dimensional array (containing control names and values) to their primary procedure in the standard module they inserted.&lt;/p&gt;
&lt;p&gt;That way they know whatever they named the control on the form will be value in the array to search to find their value.  Is there a better way for them to reference their values coming from the form?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Maybe I&#8217;m still missing something here.  If I have a form and I want to get the values off the controls on that form into a standard module procedure.</p>
<p>No matter what if I add, delete, or change a control on the form I&#8217;m going to have to manually update code somewhere. </p>
<p>Right now I have a &#8220;shell&#8221; where users in my department can insert their own module and own user form.   Then I have a procedure as part of my shell that will pass a two-dimensional array (containing control names and values) to their primary procedure in the standard module they inserted.</p>
<p>That way they know whatever they named the control on the form will be value in the array to search to find their value.  Is there a better way for them to reference their values coming from the form?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan De Schutter</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12489</link>
		<dc:creator>Johan De Schutter</dc:creator>
		<pubDate>Wed, 25 May 2005 09:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12489</guid>
		<description>&lt;p&gt;Why don&#039;t you return the data using a function with an argument thats passed by reference?&lt;/p&gt;
&lt;p&gt;The function is just a wrapper around the Show-method of the userform.&lt;/p&gt;
&lt;p&gt;Option Explicit&lt;br&gt;
Option Base 0&lt;/p&gt;
&lt;p&gt;Attribute VB_Name = &quot;GetDataUserForm&quot;&lt;/p&gt;
&lt;p&gt;Private priv_userform_result As VbMsgBoxResult&lt;/p&gt;
&lt;p&gt;Private Sub OkButton_Click()&lt;br&gt;
    On Error Resume Next&lt;/p&gt;
&lt;p&gt;    priv_userform_result = vbOK&lt;br&gt;
    Me.Hide&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Private Sub OkButton_Click()&lt;br&gt;
    On Error Resume Next&lt;/p&gt;
&lt;p&gt;    priv_userform_result = vbCancel&lt;br&gt;
    Me.Hide&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;&#039; Prevents unload of userform if the user&lt;br&gt;
&#039; clicks on the upper-right Close button&lt;/p&gt;
&lt;p&gt;Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)&lt;br&gt;
    If CloseMode = vbFormControlMenu Then&lt;br&gt;
        priv_userform_result = vbCancel&lt;br&gt;
        Cancel = 1&lt;br&gt;
        Me.Hide&lt;br&gt;
    End If&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Public Function ShowResult(ByRef selected_ids() as Integer, ByRef nbr_ids as Integer) as VbMsgBoxResult&lt;br&gt;
    On Error Resume Next&lt;/p&gt;
&lt;p&gt;    Dim ctl As Control&lt;br&gt;
    Dim i as Integer&lt;/p&gt;
&lt;p&gt;    i = 1&lt;/p&gt;
&lt;p&gt;    &#039; set id for checkboxes&lt;br&gt;
    For Each ctl In Me.Controls&lt;br&gt;
      If TypeName(ctl) = &quot;CheckBox&quot; Then&lt;br&gt;
        ctl.Value = False&lt;br&gt;
        ctl.Tag = CStr(i)&lt;br&gt;
        i = i + 1&lt;br&gt;
      End If&lt;br&gt;
    Next ctl&lt;/p&gt;
&lt;p&gt;    priv_userform_result = vbCancel&lt;br&gt;
    nbr_ids = 0&lt;/p&gt;
&lt;p&gt;    Me.Show&lt;br&gt;
    &#039; the execution continues if the user clicks&lt;br&gt;
    &#039; Ok, Cancel or Close (the userforms is hidden)&lt;/p&gt;
&lt;p&gt;    &#039; check the value of priv_userform_result&lt;/p&gt;
&lt;p&gt;    If priv_userform_result = vbOK Then&lt;/p&gt;
&lt;p&gt;      &#039; which ids are selected ?&lt;br&gt;
      For Each ctl In Me.Controls&lt;br&gt;
        If TypeName(ctl) = &quot;CheckBox&quot; Then&lt;br&gt;
          If ctl.Value Then&lt;br&gt;
             nbr_ids = nbr_ids + 1&lt;br&gt;
             ReDim Preserve selected_ids(nbr_ids)&lt;br&gt;
             selected_ids(nbr_ids - 1) = CInt(ctl.Tag)&lt;br&gt;
          End If&lt;br&gt;
        End If&lt;br&gt;
      Next ctl&lt;br&gt;
    End If&lt;/p&gt;
&lt;p&gt;    ShowResult = priv_userform_result&lt;/p&gt;
&lt;p&gt;    Unload Me&lt;br&gt;
End Function&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;In a CodeModule&lt;/p&gt;
&lt;p&gt;Dim selected_ids() as Integer&lt;br&gt;
Dim nbr_ids as Integer&lt;/p&gt;
&lt;p&gt;If GetDataUserForm.ShowResult(selected_ids, nbr_ids) = vbOK Then&lt;br&gt;
    Dim i as Integer&lt;/p&gt;
&lt;p&gt;    For i = 0 to (nbr_ids - 1)&lt;br&gt;
        Debug.Print CStr(selected_ids(i))&lt;br&gt;
    Next&lt;br&gt;
End If&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Why don&#8217;t you return the data using a function with an argument thats passed by reference?</p>
<p>The function is just a wrapper around the Show-method of the userform.</p>
<p>Option Explicit<br />
Option Base 0</p>
<p>Attribute VB_Name = &#8220;GetDataUserForm&#8221;</p>
<p>Private priv_userform_result As VbMsgBoxResult</p>
<p>Private Sub OkButton_Click()<br />
    On Error Resume Next</p>
<p>    priv_userform_result = vbOK<br />
    Me.Hide<br />
End Sub</p>
<p>Private Sub OkButton_Click()<br />
    On Error Resume Next</p>
<p>    priv_userform_result = vbCancel<br />
    Me.Hide<br />
End Sub</p>
<p>&#8216; Prevents unload of userform if the user<br />
&#8216; clicks on the upper-right Close button</p>
<p>Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)<br />
    If CloseMode = vbFormControlMenu Then<br />
        priv_userform_result = vbCancel<br />
        Cancel = 1<br />
        Me.Hide<br />
    End If<br />
End Sub</p>
<p>Public Function ShowResult(ByRef selected_ids() as Integer, ByRef nbr_ids as Integer) as VbMsgBoxResult<br />
    On Error Resume Next</p>
<p>    Dim ctl As Control<br />
    Dim i as Integer</p>
<p>    i = 1</p>
<p>    &#8216; set id for checkboxes<br />
    For Each ctl In Me.Controls<br />
      If TypeName(ctl) = &#8220;CheckBox&#8221; Then<br />
        ctl.Value = False<br />
        ctl.Tag = CStr(i)<br />
        i = i + 1<br />
      End If<br />
    Next ctl</p>
<p>    priv_userform_result = vbCancel<br />
    nbr_ids = 0</p>
<p>    Me.Show<br />
    &#8216; the execution continues if the user clicks<br />
    &#8216; Ok, Cancel or Close (the userforms is hidden)</p>
<p>    &#8216; check the value of priv_userform_result</p>
<p>    If priv_userform_result = vbOK Then</p>
<p>      &#8216; which ids are selected ?<br />
      For Each ctl In Me.Controls<br />
        If TypeName(ctl) = &#8220;CheckBox&#8221; Then<br />
          If ctl.Value Then<br />
             nbr_ids = nbr_ids + 1<br />
             ReDim Preserve selected_ids(nbr_ids)<br />
             selected_ids(nbr_ids &#8211; 1) = CInt(ctl.Tag)<br />
          End If<br />
        End If<br />
      Next ctl<br />
    End If</p>
<p>    ShowResult = priv_userform_result</p>
<p>    Unload Me<br />
End Function</p>
<p>&#8212;</p>
<p>In a CodeModule</p>
<p>Dim selected_ids() as Integer<br />
Dim nbr_ids as Integer</p>
<p>If GetDataUserForm.ShowResult(selected_ids, nbr_ids) = vbOK Then<br />
    Dim i as Integer</p>
<p>    For i = 0 to (nbr_ids &#8211; 1)<br />
        Debug.Print CStr(selected_ids(i))<br />
    Next<br />
End If</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12488</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Wed, 25 May 2005 05:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12488</guid>
		<description>&lt;p&gt;Bill -&lt;/p&gt;
&lt;p&gt;Stephen explained it nicely. My thought was incomplete; what I often do in practice is send a two-column array. Column 1 identifies some item, and column 2 identifies a value (true/false, an index, whatever). The form&#039;s code reads the list, says, &quot;Aha, item 1 is true,&quot; then highlights the item in the listbox, or checks its checkbox, or whatever.&lt;/p&gt;
&lt;p&gt;- Jon&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Bill -</p>
<p>Stephen explained it nicely. My thought was incomplete; what I often do in practice is send a two-column array. Column 1 identifies some item, and column 2 identifies a value (true/false, an index, whatever). The form&#8217;s code reads the list, says, &#8220;Aha, item 1 is true,&#8221; then highlights the item in the listbox, or checks its checkbox, or whatever.</p>
<p>- Jon</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Bullen</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12483</link>
		<dc:creator>Stephen Bullen</dc:creator>
		<pubDate>Tue, 24 May 2005 22:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12483</guid>
		<description>&lt;p&gt;Hi Bill&lt;/p&gt;
&lt;p&gt;The point is that the code outside the form &lt;i&gt;shouldn&#039;t&lt;/i&gt; know which controls the Trues and Falses refer to. In practice, you wouldn&#039;t just return an array of True/False, but rather a list of selected ID, say, or an array of the text of the selected items. So the code in the form would translate the UI shown to the user into an array of IDs or codes etc that would be exposed to the rest of the program.  By doing that, you&#039;re free to change the design of the form all you like, safe in the knowledge that you&#039;re not breaking any calling code.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Stephen Bullen&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Bill</p>
<p>The point is that the code outside the form <i>shouldn&#8217;t</i> know which controls the Trues and Falses refer to. In practice, you wouldn&#8217;t just return an array of True/False, but rather a list of selected ID, say, or an array of the text of the selected items. So the code in the form would translate the UI shown to the user into an array of IDs or codes etc that would be exposed to the rest of the program.  By doing that, you&#8217;re free to change the design of the form all you like, safe in the knowledge that you&#8217;re not breaking any calling code.</p>
<p>Regards</p>
<p>Stephen Bullen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Billkamm</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12481</link>
		<dc:creator>Billkamm</dc:creator>
		<pubDate>Tue, 24 May 2005 17:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12481</guid>
		<description>&lt;p&gt;#4 how does the program know which controls the array of trues and falses refers to?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>#4 how does the program know which controls the array of trues and falses refers to?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://www.dailydoseofexcel.com/archives/2005/05/23/getting-data-from-a-userform/#comment-12480</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Tue, 24 May 2005 13:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=1141#comment-12480</guid>
		<description>&lt;p&gt;Dick -&lt;/p&gt;
&lt;p&gt;You&#039;re still better off using all the Gets and Lets in the UserForm. This insulates the rest of the code from changes to the form&#039;s design.&lt;/p&gt;
&lt;p&gt;Say I want to change from checkboxes to a multiselect listbox. If I refer directly to the form&#039;s checkboxes, I have to hunt down all the places I refer to them, and change to whatever&#039;s appropriate for the listbox.&lt;/p&gt;
&lt;p&gt;Using Lets and Gets, for example, I can pass an array of trues and falses for what&#039;s selected and not selected, then loop through this array and check the checkbox or highlight the listbox entry within the form&#039;s code, and the calling code doesn&#039;t have to understand any of this.&lt;/p&gt;
&lt;p&gt;That&#039;s the whole reasoning behind the class module, to hide the code behind a simple interface. And Chapter 10 of Professional Excel Development says to &quot;expose properties and methods, not controls&quot;, right after &quot;use classes, not the default instance&quot;.&lt;/p&gt;
&lt;p&gt;- Jon&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Dick -</p>
<p>You&#8217;re still better off using all the Gets and Lets in the UserForm. This insulates the rest of the code from changes to the form&#8217;s design.</p>
<p>Say I want to change from checkboxes to a multiselect listbox. If I refer directly to the form&#8217;s checkboxes, I have to hunt down all the places I refer to them, and change to whatever&#8217;s appropriate for the listbox.</p>
<p>Using Lets and Gets, for example, I can pass an array of trues and falses for what&#8217;s selected and not selected, then loop through this array and check the checkbox or highlight the listbox entry within the form&#8217;s code, and the calling code doesn&#8217;t have to understand any of this.</p>
<p>That&#8217;s the whole reasoning behind the class module, to hide the code behind a simple interface. And Chapter 10 of Professional Excel Development says to &#8220;expose properties and methods, not controls&#8221;, right after &#8220;use classes, not the default instance&#8221;.</p>
<p>- Jon</p>
]]></content:encoded>
	</item>
</channel>
</rss>

