how to ADD a value of a combo box into a list box ?

Schorsch

Registered User.
Local time
Today, 22:13
Joined
Jun 20, 2002
Messages
42
Hi all,

what I want to do is the following:

on the left side of my form I have a combo box where I can select names.

now, I want to ADD values (in this case NAMES) from the combo box to a LISTBOX by pressing a button.

how can I realize that ?

thanks,
Schorsch
 
From your button you will have to modify the listbox recordsource (table,query or value list) according to the selection selected in the combo. Then apply the new modified recordsource to your listbox. Then requery and refresh the listbox.
 
I guess it depends on the row source of the list box. Lets say you have a form called frmMachine based on tblMachine. On that form you have a combo box called cboPart that is based on tblPart that holds all the part names you have to choose from. You have a list box lstConfiguration that holds all the parts that are to be include in the current machine. This would suggest a tblConfiguration that would have a foreign key of the id from tblMachine combined with the id of the part. If you simply wanted to add the selected part to tblConfiguration with the Machine id then you could put a DoCmd in the After_Update of the combo box, although you might want to prompt the user to confirm addition before going on...

DoCmd.RunSQL "INSERT INTO tblConfiguration (part_name, machine_no) VALUES (' " & Me.cboPart & " ', " & Me.machine_no & ");"

You might want to suppress the Access Append warning using...
DoCmd.SetWarnings False

... but don't forget to set them back to true when you are done.

HTH
Chris

Too slow, Alexandre beat me to it...
 
thats too complicated for me, i don't understand it, i'm a bloody access noob :(

ok, I have two tables, one called "reviewers" (thats for the combo box) and one for the listbox.

can u explain it to me step by step ? or stick an example database form on this thread ?

thanks in advance :)

regards,
Schorsch
 
I need to know what it is you are trying to do. What is the form bound to (what table)?. What is the list box bound to (what it it's row source)? What are you trying to achieve by moving values from the combo box to the list box? Are you moving numbers or text??
Chris
 
What are you trying to achieve by moving values from the combo box to the list box? Are you moving numbers or text??

text

I need to know what it is you are trying to do. What is the form bound to (what table)?. What is the list box bound to (what it it's row source)?

form is bound to TblVersionMain, the Combo Box is bound to TblApprovedBy, the ListBox to TblApprovedByList.

thank you,

Schorsch
 
This is a close parallel to the example that I gave you. :You need a procedure in the After_Update of the Combo box where you prompt the user to assure that they want to add the value, then suppress the Access warning, then append to the tblApprovedByList, then requery the list box...
I am assuming that you will want to add the primary key value from tblVersionMain to the record in tblApprovedByList and that it is called ver_no. Also that the name of the Approver in the all cases is aprv_name.

On Error GoTo EH

Dim result as int

result = msgbox("Are sure you want to add this person to the Approved By List?", vbyesno, "Append Confirm")

If result = vbyes then
docmd.setwarnings False
docmd.runsql "INSERT INTO tblApprovedByList (aprv_name, ver_no) VALUES (' " & Me.cboApprovedBy & " ', " & Me.ver_no & ");"

Me.lstApprovedByList.Requery
End if

SeeYa:
docmd.setwarnings true
exit sub

EH:
msgbox err.number & " - " & err.description
resume SeeYa

Let me now if any of this is not clear.
Chris
 
could you make me an example form ?

thanks!!

Schorsch
 

Users who are viewing this thread

Back
Top Bottom