Adding From Text Box to List BOx

  • Thread starter Thread starter Alex
  • Start date Start date
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
 
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
 
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
 
Back
Top