Adding From Text Box to List BOx

A

Alex

Hi, I want to be able to type in a value in a text box and
hit CMDADD to add it in the List Box..From there I run a
report based on those values in the list box(I got that
part) My problem is in access 2000 in vb how do u for
example add green to the list box then add Red..I dont
want to replace it..I want to add on to it. Please
Help..Thanks
 
C

Cameron Sutherland

Dim strValueIn As String
Dim strFindThis As String
Dim bolResults As Boolean
strValueIn = Me.lstBoxName.RowSource
strFindThis = """" & txtBoxName & """"
bolResults = InStr(strValueIn, strFindThis)
If Not bolResults Then
Me.lstBoxName.RowSource = strFindThis & ";" &
strValueIn
End If

-Cameron Sutherland
 
D

Dirk Goldgar

Alex said:
Hi, I want to be able to type in a value in a text box and
hit CMDADD to add it in the List Box..From there I run a
report based on those values in the list box(I got that
part) My problem is in access 2000 in vb how do u for
example add green to the list box then add Red..I dont
want to replace it..I want to add on to it. Please
Help..Thanks

It depends on whether the list box's row source is a value list or a
query. If it's a value list, you can just append the new value to the
list box's row source, preceded by a semicolon. For example:

With Me.lstSelected
.RowSource = .RowSource & ";" & Me.txtNewValue
End With

If the row source is a table (or a query of a table), you could add the
new value to that table as a new record. For example,

CurrentDb.Execute _
"INSERT INTO tblValuesSelected (ColorWanted) " & _
"VALUES('" & Me.txtNewValue & "'", _
dbFailOnError

Or you could have an "IsSelected" field in a table that contains a
record for each possible choice, and simply set that field to True --
the list box's rowsource would select only the records from that table
where IsSelected = True. Your code would then be

CurrentDb.Execute _
"UPDATE tblValuesSelected SET IsSelected = True " & _
"WHERE Color='" & Me.txtNewValue & "'", _
dbFailOnError

Me.lstSelected.Requery
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Adding to List Box 1
ADD ITEMS TO LIST BOX ACCESS 2000 3
Need help in list box 4
.AddItem 14
Limiting list box selection 2
Multi Select List Box in Access 0
Zoom box end of text 1
List Box 2

Top