Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Passing Values to Function

I have a set of textbox controls on a userform called n1,
n2 etc.

I have a common function that needs to handle each of
these controls after they are updated.

I want the name (n1, etc..) to be passed to the function
and substituted into the code that then runs against this
control. How to I pass the control name into the function?
What I have does not work!

' control n1
Private Sub n1_AfterUpdate()
ValidateNumber("n1")
End Sub

' control n2
Private Sub n2_AfterUpdate()
ValidateNumber("n2")
End Sub

'Function (example to test value passed
Private Function ValidateNumber(nBox)
MsgBox nBox.Value
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Passing Values to Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Newbie" wrote in message
...
I have a set of textbox controls on a userform called n1,
n2 etc.

I have a common function that needs to handle each of
these controls after they are updated.

I want the name (n1, etc..) to be passed to the function
and substituted into the code that then runs against this
control. How to I pass the control name into the function?
What I have does not work!



You have a couple of choices. You can pass the name to the function as you
currently do and access it through the controls collection, like

Private Function ValidateNumber(nBox)
MsgBox UserForm1.Controls(nBox).Value
End Function


or pass the textbox object and access the text property, like

' control n1
Private Sub n1_AfterUpdate()
ValidateNumber n1
End Sub

' control n2
Private Sub n2_AfterUpdate()
ValidateNumber n2
End Sub

Private Function ValidateNumber(nBox As MSForms.TextBox)
MsgBox nBox.Value
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Passing Values to Function

Thanks Bob, very helpful

"Bob Phillips" wrote in message
...


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Newbie" wrote in message
...
I have a set of textbox controls on a userform called n1,
n2 etc.

I have a common function that needs to handle each of
these controls after they are updated.

I want the name (n1, etc..) to be passed to the function
and substituted into the code that then runs against this
control. How to I pass the control name into the function?
What I have does not work!



You have a couple of choices. You can pass the name to the function as you
currently do and access it through the controls collection, like

Private Function ValidateNumber(nBox)
MsgBox UserForm1.Controls(nBox).Value
End Function


or pass the textbox object and access the text property, like

' control n1
Private Sub n1_AfterUpdate()
ValidateNumber n1
End Sub

' control n2
Private Sub n2_AfterUpdate()
ValidateNumber n2
End Sub

Private Function ValidateNumber(nBox As MSForms.TextBox)
MsgBox nBox.Value
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)






----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing values to other sheets [email protected] New Users to Excel 1 February 23rd 08 02:03 AM
Passing values in Sheet to VBA Jonathan Charts and Charting in Excel 1 June 30th 06 06:00 AM
Passing values between 2 subs ? [email protected] Excel Programming 1 November 21st 03 05:56 PM
passing values from one sheet to another BubBob[_2_] Excel Programming 1 September 4th 03 01:09 PM
Userform and passing date values DTM Excel Programming 2 July 23rd 03 04:00 AM


All times are GMT +1. The time now is 01:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"