I populate a list box on a user form with the following code:
Dim CONSTRING As String
Dim SQL As String
Dim RSSQL As New ADODB.Recordset
CONSTRING = "xxxxxxxxxx”
SQL = "SELECT [ID], [Name] FROM [Table X] WHERE Name <>'' ORDER BY [Name] ASC;"
RSSQL.Open SQL, CONSTRING, adOpenStatic, adLockBatchOptimistic, adCmdText
Set Forms!Cockpit.LB.Recordset = RSSQL
RSSQL.Close
Set RSSQL = Nothing
This code works perfectly. I can run this code as often as I want, it always populates the listbox with the expected data.
BUT: If I select one item in the Listbox and try the run the code again, it crashes everytime without returning any error code.
Any idea how to solve this? Thanks in advance..