Prev: match two conditions to return value from pivot table
Next: Number of lines in the Immediate Window
From: James on 19 May 2010 21:19 Hello, Can I do something like this.....? ............ Dim MyTextBox as Textbox TxtBoxNum = 3 Set MyTextBox = SetTheTextBoxFunc(TxtBoxNum) ............ Public Function SetTheTextBoxFunc(num as integer) as Textbox select case num case 1 SetTheTextBoxFunc = SLNX.Textbox1 case 2 SetTheTextBoxFunc = SLNX.Textbox2 case 3 SetTheTextBoxFunc = SLNX.Textbox3 end select end function ............... SLNX is a form with a bunch of textboxes. Thanks for any help. Cant quite figure this out.
From: ozgrid.com on 19 May 2010 21:33 Try; Dim MyTextBox As OLEObject -- Regards Dave Hawley www.ozgrid.com "James" <James(a)discussions.microsoft.com> wrote in message news:5A8F91F8-3ABB-464D-AE91-0FDAFEF5496E(a)microsoft.com... > Hello, Can I do something like this.....? > ........... > Dim MyTextBox as Textbox > TxtBoxNum = 3 > Set MyTextBox = SetTheTextBoxFunc(TxtBoxNum) > ........... > Public Function SetTheTextBoxFunc(num as integer) as Textbox > select case num > case 1 > SetTheTextBoxFunc = SLNX.Textbox1 > case 2 > SetTheTextBoxFunc = SLNX.Textbox2 > case 3 > SetTheTextBoxFunc = SLNX.Textbox3 > end select > end function > .............. > SLNX is a form with a bunch of textboxes. Thanks for any help. Cant > quite > figure this out.
From: Dave Peterson on 20 May 2010 08:24 This line: Dim myTextBox as TextBox is declaring myTextBox as a textbox from the Drawing toolbar (placed on a sheet, not used in a userform). Try: dim myTextBox as msforms.textbox Same with the function definition: Public Function SetTheTextBoxFunc(num as integer) as MSForms.Textbox ======= But if you've named the textboxes nicely, you could even drop the function and just use something like: Option Explicit Private Sub CommandButton1_Click() Dim myTextBox As MSForms.TextBox Dim iCtr As Long iCtr = 3 'for instance Set myTextBox = Me.Controls("Textbox" & iCtr) End Sub James wrote: > > Hello, Can I do something like this.....? > ........... > Dim MyTextBox as Textbox > TxtBoxNum = 3 > Set MyTextBox = SetTheTextBoxFunc(TxtBoxNum) > ........... > Public Function SetTheTextBoxFunc(num as integer) as Textbox > select case num > case 1 > SetTheTextBoxFunc = SLNX.Textbox1 > case 2 > SetTheTextBoxFunc = SLNX.Textbox2 > case 3 > SetTheTextBoxFunc = SLNX.Textbox3 > end select > end function > .............. > SLNX is a form with a bunch of textboxes. Thanks for any help. Cant quite > figure this out. -- Dave Peterson
From: James on 20 May 2010 11:17 Thanks, "MSForms.Textbox" was the key. I didnt try "OLEObject" I've setup naming like that before (your 2nd example) but it unfortunatly wouldn't work in this case. Thank you for the resolution! "Dave Peterson" wrote: > This line: > > Dim myTextBox as TextBox > is declaring myTextBox as a textbox from the Drawing toolbar (placed on a sheet, > not used in a userform). > > Try: > > dim myTextBox as msforms.textbox > > Same with the function definition: > > Public Function SetTheTextBoxFunc(num as integer) as MSForms.Textbox > > ======= > But if you've named the textboxes nicely, you could even drop the function and > just use something like: > > Option Explicit > Private Sub CommandButton1_Click() > Dim myTextBox As MSForms.TextBox > Dim iCtr As Long > iCtr = 3 'for instance > Set myTextBox = Me.Controls("Textbox" & iCtr) > End Sub > > > James wrote: > > > > Hello, Can I do something like this.....? > > ........... > > Dim MyTextBox as Textbox > > TxtBoxNum = 3 > > Set MyTextBox = SetTheTextBoxFunc(TxtBoxNum) > > ........... > > Public Function SetTheTextBoxFunc(num as integer) as Textbox > > select case num > > case 1 > > SetTheTextBoxFunc = SLNX.Textbox1 > > case 2 > > SetTheTextBoxFunc = SLNX.Textbox2 > > case 3 > > SetTheTextBoxFunc = SLNX.Textbox3 > > end select > > end function > > .............. > > SLNX is a form with a bunch of textboxes. Thanks for any help. Cant quite > > figure this out. > > -- > > Dave Peterson > . >
|
Pages: 1 Prev: match two conditions to return value from pivot table Next: Number of lines in the Immediate Window |