#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Combo Boxes

I have a series of combo boxes, and have created a macro to make other
boxes appear or disappear. To make the correct boxes appear, I need the
macro to select the name of the combo box that was used. ie if it was
"dd1" i need a function that will return this to a string.

Any ideas?

T

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Combo Boxes

Trystan,

Try this

Function ReturnCBOName(optional byval cboBox as MSForms.ComboBox) As String
ReturnCBOName = cboBox.Name
End Function

when you call the function in any procedure use the following
Assigning to a string variable:
strVariable = ReturnCBOName(your_combo_box_Name)
Other Reason (sample "IF" statement)
If ReturnCBOName(your_combo_box_Name) = "Your Result If TRUE" then
End If

Best Luck.


Ronin


"Trystan" wrote:

I have a series of combo boxes, and have created a macro to make other
boxes appear or disappear. To make the correct boxes appear, I need the
macro to select the name of the combo box that was used. ie if it was
"dd1" i need a function that will return this to a string.

Any ideas?

T


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Combo Boxes

Thanks for the help - much appreciated - however when I step through, i
get a run time error 91 - object variable or with block variable not
set - hav i forgotten to add anything?

Thanks

T

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Combo Boxes

More likely the error is happening with in the function.

If that's the case, specify your current combo box... not the property of
the combobox... sample:

ReturnCBOName(your_combo_box_name) '<--- Correct way

ReturnCBOName(your_combo_box_name.ListIndex) '<--- Incorrect

This way... you have all (every thing) the information within the combobox.
Like the listed items, properties, etc...

If this is not happening in the function... post the basic information...
either... how you are calling it and or the function itself so i could
analyze it.



Thanks in advance


"Trystan" wrote:

Thanks for the help - much appreciated - however when I step through, i
get a run time error 91 - object variable or with block variable not
set - hav i forgotten to add anything?

Thanks

T


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Combo Boxes

I've got that working however I have to enter the name of the combobox
that I am working on (your_combo_box_name) - this is the value I am
trying to get see my code below:

So for instance I need to get currentcomboboxname so that I can use it
to specify the other shapes - currently "ot12" and "mt12" - can i do
that with his code? - am I missing something here ?

strVariable = ReturnCBOName(currentcomboboxname)

If Range("D12").Value = "Other" Then
ActiveSheet.Shapes("ot12").Visible = True
ActiveSheet.Shapes("mt12").Visible = True
Else:
If ActiveSheet.OLEObjects("ot12").Object.Text = "" Then
ActiveSheet.OLEObjects("ot12").Visible = False
ActiveSheet.OLEObjects("mt12").Visible = False
Else
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "You have already entered text in a field. Press Yes
to continue and delete all text, press No to return." ' Define
message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define
buttons.
Title = "Error" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
ActiveSheet.OLEObjects("ot12").Object.Text = ""
ActiveSheet.OLEObjects("mt12").Visible = False
ActiveSheet.OLEObjects("ot12").Visible = False
Else ' User chose No.
Range("D12").Value = "7"
End If

End If
End If

End Sub


Function ReturnCBOName(Optional ByVal cboBox As MSForms.ComboBox) As
String
ReturnCBOName = cboBox.Name
End Function



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Combo Boxes

Trystan,

If you want the value selected in the combobox, then in the function:

Function ReturnCBOName(Optional ByVal cboBox As MSForms.ComboBox) As
String
ReturnCBOName = cboBox.Text '<--- or you could subtitute
cboBox.Column(#) <--- # represents what ever column has your value.
End Function

But i'm not sure what you're wanting it to do... return combo box's name or
value?
else if you want other object to be evaluated:

Function ReturnName(Optional ByVal mObject) As
String
ReturnName = mObject.Name
End Function

notice after "ByVal" the rest of the characters were changed or removed
(cboBox As MSForms.ComboBox) befor the ")". this allows you to send any
object/control to the function to be evaluated and the "ReturnName becomes
like avariable that stores the value to return to the calling procedure...
meaning

ReturnName = mObject.Name '<--- this assigns the name of the object to the
function ReturnName


so when you got a procedure and within the procedure you call the function
like this (and this is just an example),

Private Sub UserForm_Activate()

Dim strStorageName As String*50
strStorageName = ReturnName(MyShape) '<-- once the code has finish
running function (ReturnName)... strStorageName then have the string name of
the "MyShape"

End Sub



Ronin
"Trystan" wrote:

I've got that working however I have to enter the name of the combobox
that I am working on (your_combo_box_name) - this is the value I am
trying to get see my code below:

So for instance I need to get currentcomboboxname so that I can use it
to specify the other shapes - currently "ot12" and "mt12" - can i do
that with his code? - am I missing something here ?

strVariable = ReturnCBOName(currentcomboboxname)

If Range("D12").Value = "Other" Then
ActiveSheet.Shapes("ot12").Visible = True
ActiveSheet.Shapes("mt12").Visible = True
Else:
If ActiveSheet.OLEObjects("ot12").Object.Text = "" Then
ActiveSheet.OLEObjects("ot12").Visible = False
ActiveSheet.OLEObjects("mt12").Visible = False
Else
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "You have already entered text in a field. Press Yes
to continue and delete all text, press No to return." ' Define
message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define
buttons.
Title = "Error" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
ActiveSheet.OLEObjects("ot12").Object.Text = ""
ActiveSheet.OLEObjects("mt12").Visible = False
ActiveSheet.OLEObjects("ot12").Visible = False
Else ' User chose No.
Range("D12").Value = "7"
End If

End If
End If

End Sub


Function ReturnCBOName(Optional ByVal cboBox As MSForms.ComboBox) As
String
ReturnCBOName = cboBox.Name
End Function


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
Getting Combo boxes to change options based on other Combo boxes. Ancient Wolf New Users to Excel 1 March 27th 09 06:29 PM
Selecting subsets using combo boxes or list boxes CLamar Excel Discussion (Misc queries) 0 June 1st 06 07:43 PM
Questions on combo boxes and list boxes. Marc New Users to Excel 1 March 14th 06 09:40 AM
Combo Boxes and Tick Boxes turner2000 Excel Programming 0 September 28th 04 10:01 PM
List boxes/combo boxes Tibow Excel Programming 3 February 17th 04 12:35 PM


All times are GMT +1. The time now is 12:38 PM.

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

About Us

"It's about Microsoft Excel"