If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > combo box / label box relationship

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-06-06, 10:33
mike703 mike703 is offline
Registered User
 
Join Date: Mar 2005
Posts: 23
combo box / label box relationship

Ok, I know this can be done but am having the darndest time in figuring it out. What I am trying to do is when a selection from the combo box is chosen the selection will simultaneously show in the label box. I have come very close but have not completely achieve my goal. This is what I have thus far....


Private Sub LblMthWk_Click()

If CmbMthWk = "MONTHLY" Then
LblMthWk.Caption = "Monthly"

ElseIf CmbMthWk = "WEEKLY" Then
LblMthWk.Caption = "Weekly"

End If

End Sub

CmbMthWk is a combo box where the user would select either monthly or weekly. LblMthWk is the label box in which I would like the selection to show. As you can see from the code the selection will only show if the label box is clicked (which I do not want since I am attempting to make the label box transparent). I have tried to change the event from Private Sub LblMthWk_Click() to Private Sub LblMthWk_Change(), but then it does absolutely nothing after the choice has been made. Any help given would be greatly appreciated!
Reply With Quote
  #2 (permalink)  
Old 09-06-06, 20:14
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
You have the idea somewhat. But, if I understand what you are trying to do; Change the Label object on the action that occurs to the Combo Listbox object. Then you must use the Event procedure of the Combobox not the label.

You are going to create an event procedure in the class module of your userform. Suppose you have a label "Label1" and a ComboBox "ComboBox1" You can simply use the Change event of the combo box to change the Lable1 text whenever the list changes.
Code:
Private Sub ComboBox1_Change()
Me.Label1 = Me.ComboBox1.Value
End Sub
I used "Me" to identify the UserForm object in the above example. This is optional for code in the userforms class, but a good idea to qualify the object. If you want to write a more extensive Sub procedure you may not want all the code in the UserForm module but you still have to use the userform module to capture the combo list change action. When referring to the userform outside of the UserForm Module you must use the name of the Userform to qualify form controls like this.
Code:
' Event procedure in the userfrom Module
Private Sub ComboBox1_Change()
Call SetLabel
End Sub

' Calling this Procedure in a module under Modules
Sub SetLabel()
UserForm1.Label1 = UserForm1.ComboBox1.Value

End Sub
This is code you can use to populate a combobox and test the process. Create a user form with the Label1 and ComboBox1 controls and paste the code in the userforms code Module
Code:
Private Sub ComboBox1_Change()
Me.Label1 = Me.ComboBox1.Value
End Sub

Private Sub UserForm_Activate()
vString = Array("one", "Two", "Three")
Me.ComboBox1.List = vString
End Sub
__________________
~

Bill
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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