PDA

View Full Version : Create 1 Public Sub for 5 textboxes



av8tordude
02-01-2011, 07:19 PM
I have 5 date-boxes (Date1, Date2, Date3, etc) on a multipage. I have this code in each of the date boxes. How can I create a public sub that I can reference to this code, but substitute the Date-box's name

Thanks

If LenB(Range("B11").Value) > 0 Then
If Year(Date5) <> Year(Range("B11").Value) Then
Ent5.Enabled = False
If Not AlreadyShown Then
MsgBox "You may not register a FY" & Year(Date5) & " expense in a FY" & Year(Range("B11")) & " Expense Report Log."
AlreadyShown = True
End If
End If
End If

Kenneth Hobs
02-01-2011, 07:29 PM
The concept is simply shown here.Sub ShowTextboxValue(ByVal tbx As MSForms.TextBox)
MsgBox tbx.Value
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ShowTextboxValue TextBox1
End Sub

av8tordude
02-01-2011, 07:32 PM
I don't quite understand your post. Could you elaborate

Thanks

frank_m
02-02-2011, 04:40 AM
I believe what the example does is upon exiting TextBox1, a msgbox will popup showing you the value in TextBox1

Kenneth Hobs
02-02-2011, 07:41 AM
IF you type MSForms and a period, you may be able to pick a date control type. I don't have a date control since I use Excel 2010 and Vista64. This is why I gave a TextBox control example.

The Private sub has the MSForms. type so set it there. The Sub ShowTextboxValue would contain your code. The input parameter value you set with the MSForms type is what you use in your code.

The Private Sub is how you would send that control to your public sub SHowTextboxValue.