I have a list box that is linked to a specified query in the QueryDefs of my CurrentDB. This list shows always the correct items. Further I use the function below to extract the information from the list. This always succeeds the first time. But after having manipulated the query that the list is based on (the list is showing the right result), I often get error 3420: "Object no longer set" or error 3219: "invalid operation". Any ideas?
YS. ViAn
See the code below:
YS. ViAn
See the code below:
Code:
Private Function ID_string() As String
'Making a string on format: "ID IN (2, 4, 5) "
Dim rst As DAO.Recordset
Dim nrOfRecords As Long
Dim idx As Long
Dim dbs As Database
Dim tmpString As String
Set dbs = CurrentDb
Set rst = Forms!myForm!myList.Recordset
rst.MoveFirst ''' OOPS! Here error 3420 occurs
tmpString = "ID IN ("
nrOfRecords = rst.RecordCount ''' OOPS! Here error 3219 occurs
For ii = 0 To (nrOfRecords - 1)
tmpString = tmpString & rst.Fields("ID").Value
If ii < (nrOfRecords - 1) Then
tmpString = tmpString & ", "
rst.MoveNext
End If
Next ii
tmpString = tmpString & ")"
ID_string = tmpString
End Function