Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default value from cbo box and text box

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default value from cbo box and text box

Thank you very much for your help Dave, it worked wonderfuly.

I stay clear from a chk boxes because the graphical representation of a chk
box with no Value is a grayed out check mark inside the chk box, this might
confuse people. For my DB i need to collect yes, no and also a blank value.

I have the rowsource of the cbo set to "=Sheet1!A5:A7", this is where A5
has no text, A6 shows "YES", and A7 shows "NO".

Is this code supposed to replace my RowSource under the cbo properties?
What is its function?

Private Sub UserForm_Initialize()
With Me.cboNameMatch
.AddItem "YES"
.AddItem "NO"
.AddItem ""
End With
End Sub

Thank you.



"Dave Peterson" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default value from cbo box and text box

Yep. I didn't know how you created the cbonamematch combobox. It seemed pretty
easy for my testing to just add the items.

And less dangerous, too...

If I'm using a rowsource, I like to keep it on a hidden sheet. Then I know
it'll be much more difficult for the average user (including me) to mess it up
(inserting/deleting rows or columns--or changing data).

Memphis wrote:

Thank you very much for your help Dave, it worked wonderfuly.

I stay clear from a chk boxes because the graphical representation of a chk
box with no Value is a grayed out check mark inside the chk box, this might
confuse people. For my DB i need to collect yes, no and also a blank value.

I have the rowsource of the cbo set to "=Sheet1!A5:A7", this is where A5
has no text, A6 shows "YES", and A7 shows "NO".

Is this code supposed to replace my RowSource under the cbo properties?
What is its function?

Private Sub UserForm_Initialize()
With Me.cboNameMatch
.AddItem "YES"
.AddItem "NO"
.AddItem ""
End With
End Sub

Thank you.

"Dave Peterson" wrote:

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


--

Dave Peterson
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
Using TEXT and &TEXT - display numbers with commas, underline text Gary Excel Discussion (Misc queries) 3 May 5th 23 03:46 AM
Text does not display in "Text boxs" and when wrapping text in a c Esteban Excel Discussion (Misc queries) 1 March 8th 07 11:59 PM
select text in cell based on text from another cell, paste the text at the begining of a thrid cell, etc... jsd219 Excel Programming 0 October 19th 06 05:04 PM
Excel VBA: Worksheet cell .Text property: 1024 bytes text len limit loyso Excel Programming 7 May 3rd 05 02:51 PM
extracting text from within a cell - 'text to rows@ equivalent of 'text to columns' Dan E[_2_] Excel Programming 4 July 30th 03 06:43 PM


All times are GMT +1. The time now is 04:34 AM.

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"