View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default value from cbo box and text box

I created a small userform with a combobox and two textboxes and named them
nicely.

This was the code I used behind the userform:

Option Explicit
Private Sub cboNameMatch_Change()
If UCase(Me.cboNameMatch.Value) = UCase("YES") Then
Me.txtUserNameAllegation.Value = Me.txtUserName.Value
Else
Me.txtUserNameAllegation.Value = ""
End If
End Sub
Private Sub UserForm_Initialize()
With Me.cboNameMatch
.AddItem "YES"
.AddItem "NO"
.AddItem ""
End With
End Sub

The "Me" in the code is the keyword for the object that owns the code--in this
case, my userform. (I don't need to use its name.)

And if I changed (really changed!) the value in the combobox, the textboxes
updated right away.

But if I tried to change from Yes to Yes, then that really isn't a change, so
nothing happened.

If this works for you in a test userform, try it in your real userform.

Just a curiousity question...

Why do you have "" as an option in that combobox?

And since you're only using two options (Yes/No), you could use a checkbox or
even a pair of optionbuttons.


Memphis wrote:

Hello,
So, I have a txtbox1, a combo box, and txt box2
txtbox1 has the user's name, the combo box has "Blank", "YES", and "NO".
I need the cbo box to copy the data from txtbox1 to txtbox2 if the selection
is "YES". I would like for this to happen instantly.
I also want the value to remain blank in txtbox2 if the cbo has no value
("Blank").
My problem comes when I click YES and then it copies the data to txtbox2 and
if I need to change the value to either Blank or NO, the data does
not update until I change the focus to another object.

This does not occurr with a check box, things happen instantly, so why can't
this also happen by selecting a value from a cbobox?

Having said this, a chk box has only two values, this one has 3 values,
perhaps this is where the problem lies.

here is my code..

Thank you for your help.

Private Sub cboNameMatch_Change()
If MatchAllegation_01.cboNameMatch.Value = "YES" Then
MatchAllegation_01.txtUserNameAllegation.Value =
MatchAllegation_01.txtUserName.Value
ElseIf MatchAllegation_01.cboNameMatch.Value = "NO" Or
MatchAllegation_01.cboNameMatch.Value = "" Then
MatchAllegation_01.txtUserNameAllegation.Value = ""
End If
End Sub


--

Dave Peterson