Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add records to a list box

Status
Not open for further replies.
Jun 26, 2001
41
US
I am new to access and can't figure out how to do this. I have six combo boxes that the user choses from. When 0 or all combo boxes are selected, records are displaed in a list box pertaining to what was selected. Now I want it so the when the user selects fields in the combo boxes the records will keep being added in the list box and not being refreshed everytime. If any one has any insight I would greatly appreciate it.

Here is my code

Private Sub cmdAdd_Click()

Dim critstr As String
Dim x As Integer

For x = 1 To 6 'Loop 6 Times
If Me(&quot;combo&quot; & x) <> &quot;&quot; Then
critstr = critstr & Me(&quot;combo&quot; & x).Tag & &quot; = '&quot; & Me(&quot;combo&quot; & x) & &quot;' And &quot;
End If
Next x


If Len(critstr) > 5 Then
critstr = Left(critstr, Len(critstr) - 5)
End If

Me.picList1.RowSource = &quot;SELECT Distinct AnimalID, ChemName, Dose, BluePlaque FROM Generate1 WHERE &quot; & critstr & &quot;&quot;

End Sub

Thanks,
Byron
 
records and columns in a combo box if it is not using a controlsource property are delimited using a semicolon and comma. To add a two column record to a combo box the string would look like this:


Row
-------------------------------
Column1 Column2
-------------- ---------------
&quot;Column 1 data, Column 2 data;&quot;


strNewRow = &quot;Column 1 data, Column 2 data;&quot;
Me.Combo1.RowSourceType = &quot;Value List&quot; 'Value List ???
Me.Combo1.RowSource = Me.Combo1.RowSource & strNewRow

.RowSourceType might have to be assigned an integer value
representing 'Value List'.

Steve King
Growth follows a healthy professional curiosity
 
Thanks for the response but I am trying to figure out how I would add a new row of records to a list box. I want it so when the user hits the add button it keeps adding rows of records to the list box.

Example:

The user selects data from the combo boxes. The user hits the add button and it displays data corresponding to what was selected in the combo boxes. Then I want it to be able to when the user hits the add button again itstead of replacing the list box with the new data it would add that data to the list box underneath what was already displayed. Hopefully what I wrote makes sense.

Thanks,
Byron
 
Byron,

Actually the combobox and listbox are handled the same, so even though my example shows a combobox, you can use it for a listbox.

Actually my delimiters were backwards though. It's a semicolon for columns and a comma for rows. Here is an extract from my code where I have four columns; a participant's id, a role for the participant, a False, and a participant's name built off a candidate listbox, and a long name for the role.

Steve King

Me.ParticipantList.RowSource = Me.ParticipantList.RowSource _
& mstrCandidateIdentifier & &quot;;&quot; & mstrRole & &quot;;False;&quot; _
& DecodeName(mstrCandidateName) & &quot;;&quot; & mstrLongRole & &quot;,&quot;

Steve King Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top