By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,400 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,400 IT Pros & Developers. It's quick & easy.

Update Single Textbox with multiple subjects from combobox

P: 34
Hi friends

in a student database i created a combobox contain subjects eg english/ physics/chemistry/psychology/Arabic etc
and a textbox named selected subjects.

now the question is how to add multiple any choice selected subjects from combobox to textbox in this way.

English-Physics-Arabic
Oct 20 '20 #1

✓ answered by SioSio

What kind of error do you get?
In some cases, rewriting the combobox's property ".Text " to ".Value" may eliminate the error.

Share this Question
Share on Google+
16 Replies

100+
P: 200
Expand|Select|Wrap|Line Numbers
  1. If TextBox1.Text = "" Then
  2.     TextBox1.Text = ComboBox1.Text
  3. Else
  4.     TextBox1.Text = TextBox1.Text & "-" & ComboBox1.Text
  5. End If
Oct 20 '20 #2

P: 34
Code Error Bro

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo0_Click()
  2. If Text3.Text = "" Then
  3.     Text3.Text = Combo0.Text
  4. Else
  5.     Text3.Text = Text3.Text & "-" & Combo0.Text
  6. End If
  7. End Sub
Oct 20 '20 #3

100+
P: 200
What kind of error do you get?
In some cases, rewriting the combobox's property ".Text " to ".Value" may eliminate the error.
Oct 20 '20 #4

P: 34
see image for error. i dont know whats the error.

the combobox name is combo0 and the textbox name text3
Oct 20 '20 #5

P: 34
See the image for error.

Combobox name combo0
textbox name text3


code entered on click event of combobox
Attached Images
File Type: jpg ddddddd.jpg (11.4 KB, 11 views)
Oct 20 '20 #6

100+
P: 200
If you get an error in this statement, the object(Text3) may be named incorrectly.
Oct 20 '20 #7

100+
P: 200
Converting Null to a zero-length string with the Nz function and comparing it may work.
Expand|Select|Wrap|Line Numbers
  1. If Nz(Me!Text3, "") <> "" Then
Oct 20 '20 #8

P: 34
No SioSio i tried simple code and it worked like

me.text3.text = me.combo0.text

the single text updated

but this code not working
Oct 20 '20 #9

100+
P: 200
Try this code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo0_Change()
  2.     'If Me.Text3.Text = "" Then
  3.     If Nz(Me.Text3.Text, "") = "" Then
  4.         Me.Text3.Text = Combo0.Text
  5.     Else
  6.         Me.Text3.Text = Me.Text3.Text & "-" & Combo0.Text
  7.     End If
  8. End Sub
  9.  
Oct 20 '20 #10

P: 34
i put this code in vba no error but also not work... i am using Office 2013
Oct 20 '20 #11

100+
P: 200
I'm sorry. I made a mistake.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo0_Change()
  2.     'If Me!Text3.Text = "" Then
  3.     If Nz(Me!Text3.Text, "") = "" Then
  4.         Me!Text3.Text = Me!Combo0.Text
  5.     Else
  6.         Me!Text3.Text = Me!Text3.Text & "-" & Me!Combo0.Text
  7.     End If
  8. End Sub
  9.  
Oct 20 '20 #12

P: 34
Debug mistake error in this part
Expand|Select|Wrap|Line Numbers
  1. If Nz(Me!Text3.Text, "") = "" Then
Oct 20 '20 #13

P: 34
how if you made an access file and share with me ?
Oct 20 '20 #14

twinnyfo
Expert Mod 2.5K+
P: 3,548
All,

There should be no need to use either the .Text or .Value properties of a Combo Box. The Default property Me.ComboBoxName is .Value.

Also, rather than using the OnChange event, it may be best to use the AfterUpdate event.

Granted, much of this is preference--but I've just had a few too many headaches working with things in such a manner.

Hope this hepps.
Oct 20 '20 #15

100+
P: 200
With UserForm_Initialize ()
If you set
Expand|Select|Wrap|Line Numbers
  1. Text3.Text = ""
,
Expand|Select|Wrap|Line Numbers
  1. If Me! Text3.Text = "" Then
Is OK.
Oct 20 '20 #16

P: 34
yes now it worked .... thanks bro

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Initialize()
  2. Me.Text3 = ""
  3. End Sub
  4.  
  5.  
  6. Option Compare Database
  7. Private Sub Combo0_Change()
  8.  
  9.     If Me.Text3 = "" Then
  10.         Me.Text3 = Me.Combo0
  11.     Else
  12.         Me.Text3 = Me.Text3 & "-" & Me.Combo0
  13.     End If
  14. End Sub
  15.  
  16.  
  17.  
Oct 21 '20 #17

Post your reply

Sign in to post your reply or Sign up for a free account.