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