473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Selection from combobox and populate multiple fields by separate clicks

58 32bit
Hello friends need your help once again.


i am trying to make a combobox of education subjects i will put all subjects to one combobox and i made 4 text boxes subject1 subject2 subject3 and subject4.

now i want to select one subject for example english

then it must enter to Subject1 another selection Maths to subject2 same others. in simple words one combobox multiple selections to one by one textbox.


how it will possible ?
Oct 13 '20 #1

✓ answered by ADezii

I created a simple Demo for you that will hopefully explain everything in detail.

21 2150
SioSio
272 256MB
This sample code looks for a control in UserForm1 that has "subject" in its name. If that value is blank, enter the value you selected in combobox1.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboBox1_Change()
  2.     For Each cntrl In UserForm1.Controls
  3.         If cntrl.Value = "" And InStr(cntrl.Name, "subject") > 0 Then
  4.             cntrl.Value = ComboBox1.Text
  5.             Exit For
  6.         End If
  7.     Next
  8. End Sub
  9.  
  10. Private Sub UserForm_Initialize()
  11.     ComboBox1.AddItem "mathmatics"
  12.     ComboBox1.AddItem "social studies"
  13.     ComboBox1.AddItem "history"
  14.     ComboBox1.AddItem "geography"
  15.     ComboBox1.AddItem "civics"
  16.     ComboBox1.AddItem "ethics"
  17.     ComboBox1.AddItem "chemistry"
  18.     ComboBox1.AddItem "physics"
  19.     ComboBox1.AddItem "earth science"
  20.     ComboBox1.AddItem "arts"
  21.     ComboBox1.AddItem "music"
  22. End Sub
Oct 13 '20 #2
ZKAHADI
58 32bit
this code must be great but i am searching for something different.
see the image
there is a combobox and 3 text boxes
i want select any subject from combobox and it the text will enter into first text box and same any subject selection will enter to another box.

Oct 13 '20 #3
SioSio
272 256MB
If you want to enter the same data in all textboxes, try removing the "exit for" statement from the sample code.
Oct 13 '20 #4
ZKAHADI
58 32bit
no brother if a student have 3 subjects for example maths english and physics i want put these three subjects from combobox to separate textboxes. not necessary that i will put maths english physics i can put enlish physics maths or physics maths english. but i want click subject name from combobox and put data one by one into boxes
Oct 13 '20 #5
SioSio
272 256MB
I'm sorry, my English comprehension doesn't quite tell you what you want to do.
Maybe you need another combobox to select a language?
Oct 13 '20 #6
ZKAHADI
58 32bit
let me simple because i am also weak in english.

combo box ..... English
Physics
Biology
Maths
Chemistry

SubjectText1........ SubjectText2........ SubjectText3.........

i want to click and put my choice subject from combobox to SubjectText1
then i want click combobox select my choice another subject to put in subjectText2
same combobox select my choice subject to subjectText3
Oct 13 '20 #7
SioSio
272 256MB
The sample code shown at the beginning is sufficient for that requirement.

An easier way is to make everything comboboxes instead of using text boxes.
Oct 13 '20 #8
ADezii
8,834 Expert 8TB
  1. Instead of a Combo Box, create a List Box on your Form (lstSubjects).
  2. Set the MultiSelect Property of this List Box to Extended.
  3. Create four Text Boxes on your Form named sequentially from Text1, Text2, Text3, and Text4.
  4. Copy-N-Paste then following Code into the Click Event of a Command Button. It will check to see that only a Maximum of four Items in lstSubjects has been selected, then write those selections to Text1, Text2, Text3, and Text4
Expand|Select|Wrap|Line Numbers
  1. Dim varItm As Variant
  2. Dim intCtr As Integer
  3. Dim intCtr2 As Integer
  4.  
  5. 'Clear the Text Boxes
  6. For intCtr2 = 1 To 4
  7.   Me.Controls("Text" & CStr(intCtr2)) = Null
  8. Next
  9.  
  10. If Me![lstSubjects].ItemsSelected.Count = 0 Then
  11.   Exit Sub
  12. ElseIf Me![lstSubjects].ItemsSelected.Count > 4 Then
  13.   MsgBox "You can only a Maximum of 4 Subjects", vbExclamation, "Invalid Entry"
  14. Else    '3 or more Items were selected
  15.   For Each varItm In Me![lstSubjects].ItemsSelected
  16.     intCtr = intCtr + 1
  17.     Me.Controls("Text" & CStr(intCtr)) = Me![lstSubjects].ItemData(varItm)
  18.   Next
  19. End If
Oct 13 '20 #9
SioSio
272 256MB
If you organize the requirements with my understanding
1. Empty the four text boxes.
2. When you select one item from combobox1, it will always be entered in SubjectText1.
3. Make the 1st selected item not selectable from combobox1.
4. When you select the 2nd item from combobox1, it will always be entered in SubjectText2.
5. Make the 2nd and 3rd selected items not selectable from combobox1.
6. When you select the 3rd item from combobox1, it will always be entered in SubjectText3.
7. Make the 1st, 2nd and 3rd selected items not selectable from combobox1.
8. When you select the 4th item from combobox1, it will be filled in SubjectText4.

Is it the flow of this process? If so, please point out what is different.
Oct 14 '20 #10
SioSio
272 256MB
Hi ADezii.
In my environment, the code you showed didn't work, so I fixed it a bit to make it work.
Your idea, Listbox, will prevent it from selecting the same item.

Expand|Select|Wrap|Line Numbers
  1.     'Dim varItm As Variant
  2.     Dim intCtr As Integer
  3.     Dim intCtr2 As Integer
  4.     Dim mSelectItem As Integer
  5.  
  6.     'Clear the Text Boxes
  7.     For intCtr2 = 1 To 4
  8.       Me.Controls("SubjectText" & CStr(intCtr2)) = Null
  9.     Next
  10.  
  11.     'Set Selected items count
  12.     mSelectItem = 0
  13.     For intCtr2 = 0 To Me![lstSubjects].ListCount - 1 '
  14.         If lstSubjects.Selected(intCtr2) Then
  15.             mSelectItem = mSelectItem + 1
  16.         End If
  17.     Next
  18.  
  19.     'If Me![lstSubjects].ItemsSelected.Count = 0 Then
  20.     If mSelectItem = 0 Then
  21.       Exit Sub
  22.     'ElseIf Me![lstSubjects].ItemsSelected.Count > 4 Then
  23.     ElseIf mSelectItem > 4 Then
  24.       MsgBox "You can only a Maximum of 4 Subjects", vbExclamation, "Invalid Entry"
  25.     Else    '3 or more Items were selected
  26.       intCrt = 0
  27.       'For Each varItm In Me![lstSubjects].ItemsSelected
  28.       For intCtr2 = 0 To Me![lstSubjects].ListCount - 1
  29.         If Me![lstSubjects].Selected(intCtr2) Then
  30.             intCtr = intCtr + 1
  31.             'Me.Controls("Text" & CStr(intCtr)) = Me![lstSubjects].ItemData(varItm)
  32.             Me.Controls("SubjectText" & CStr(intCtr)) = Me![lstSubjects].List(intCtr2)
  33.          End If
  34.       Next
  35.     End If
Oct 14 '20 #11
ZKAHADI
58 32bit
something error not working code.
please check below image


https://i.imgur.com/B7PIZjQ.jpg
Oct 14 '20 #12
SioSio
272 256MB
In my network environment, I cannot see the posted link for my security reasons.
Use the "Insert Image" feature in the combobox of "Post your reply".
Oct 14 '20 #13
ZKAHADI
58 32bit
image attached kindly find the image and solve the problem
Attached Images
File Type: jpg ed.jpg (98.2 KB, 62 views)
Oct 14 '20 #14
SioSio
272 256MB
Try it with the code shown by ADezii.
The operation is the same.
Oct 14 '20 #15
ZKAHADI
58 32bit
The code is not working or i am not understanding to use it. could your please make a form and upload for me? please
Oct 14 '20 #16
SioSio
272 256MB
I will explain with the code of ADezii.
The names of the TextBox are "Text1", "Text2", "Text3", and "Text4", respectively.
The name of the ListBox is "lstSubjects".
Set "MultiSelect Property" of ListBox (lstSubjects) to Extended.
If you want to select multiple items from the Listbox, hold down the Shift key while using the mouse.
Oct 14 '20 #17
ZKAHADI
58 32bit
i did what you said but on clicking button nothing happen not even error but no data putting in boxes.. look at image please
Attached Images
File Type: jpg itled.jpg (77.3 KB, 41 views)
Oct 14 '20 #18
i want select any subject from combobox and it the text will enter into first text box and same any subject selection will enter to another box. mobdro apk tubemate
Oct 14 '20 #19
SioSio
272 256MB
Looking at the image file of post # 14, is the name of the "Add" button Command23?

I think the position to write the code is correct.

If that doesn't work, try setting a breakpoint on any line (for example, line 6) and using the F8 key to run it line by line.
Oct 14 '20 #20
ADezii
8,834 Expert 8TB
I'll Upload a Demo sometime today which will make things much clearer for you.
Oct 14 '20 #21
ADezii
8,834 Expert 8TB
I created a simple Demo for you that will hopefully explain everything in detail.
Attached Files
File Type: zip Subjects.zip (23.3 KB, 36 views)
Oct 14 '20 #22

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

Similar topics

3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
1
by: girjer | last post by:
I want to populate two table fields on a selection of either combo box, list box or any option button. For e.g. When I select 'YES' as an option I want to populate two fields in the table i.e....
1
by: GODSPEEDELECTRONICS | last post by:
I have a form, where users enter an order # (key) and who they are. All in table (see links below). From there, I want them to be able to enter the NSN # (combobox) and have the description,...
2
by: Nathan Sokalski | last post by:
I have a Repeater that uses a DataSource that has multiple fields. When the values of these fields is displayed in the Repeater, there are fields that are used in combination with other fields as...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
3
Michael Adams
by: Michael Adams | last post by:
I have been working on this form for quite some time with alot of help from this forum and its users. Everyone has been very helpful and there are great solutions from everyone. I also posted a...
2
by: Horace Martin | last post by:
How do I populate multiple fields on a form by using a combo box. My combo box has 3 col. When I make a selection from my combo box all 3 fields should be filled in on my form. eg. Form Fields:...
32
LeighW
by: LeighW | last post by:
Hi, I'm still having a couple problems with searches. I have a search form, frm_Search. The form I am trying to filter, frm_Form1 An unbound combobox on frm_Search, Cbo_Permit 6 different...
4
by: cnstarz | last post by:
Hi! I'm basically emulating a split form by having a subform in datasheet view that displays all the records of a table. Clicking on a record in the subform populates the mainform with the record's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.