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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box Adds Two Items Instead Of one

Status
Not open for further replies.

mordja

Programmer
Apr 27, 2004
294
GB

Hi,

I have a list box. Initially it's rowsource is a table query. I populate it then change its rowsource to value list so that I can make additions to it. This process is going to be run on the on current and load events of the form, I want it to occur for each record.

Firstly

Private Sub Form_Load()
strCategoryUsageSource = "SELECT [VolAloc_tlkpCategoryUsage].[Category] FROM " _
& " [VolAloc_tlkpCategoryUsage] WHERE [VolAloc_tlkpCategoryUsage].[AllocationType] " _
& "= [Forms]![VolAloc_frmAllocationControls]![AllocationType] ;"
Me.lstCategoryUsage.RowSourceType = "Table/Query"
Me.lstCategoryUsage.RowSource = strCategoryUsageSource
Call ChangeListType(strCategoryUsageSource, Me.lstCategoryUsage)
End Sub


The change list type is as follows

Private Sub ChangeListType(ByVal strSQL As String, lstControl As ListBox)

Dim strValueList As String
Dim i As Integer

lstControl.RowSourceType = "Table/Query"
lstControl.RowSource = strCategoryUsageSource

For i = 0 To lstControl.ListCount - 1
strValueList = strValueList & lstControl.ItemData(i) & ";"
Next i

RTrim strValueList
lstControl.RowSourceType = "Value List"
lstControl.RowSource = strValueList
End Sub


Lastly the list is added to by

Private Sub cmdCategoryAdd_Click()
If Not Me.txtCategorySelection.Value = "" Then
Me.lstCategoryUsage.AddItem (Me.txtCategorySelection)
End If
End Sub


This all works fine, the listbox is populated and its row source type is change and I can make additions to it. The problem is that the first time I add to it, it adds two items - a blank item and the one I wanted. After that it works fine. Any ideas

Mordja
 

Got it. the AddItem() of a list box adds a ; before the item not after.

Mordja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top