Well you learn something all the time. I worked on it a while and it turns out you can't add a udt to a collection.However, if you are willing to parse a string later on when to want to read the data in the collection then you can do this.
------------------Code:Public MyCollection As New Collection Private Sub Command1_Click() Dim intIndex As Integer ' This is just test data, and obviously you wouldn't want to ' hard-code the data values. I assume instead that the data would ' come from TextBoxes, etc. and you would only try to add/update ' one record at a time. If RecordExits(111, "site 1", "Marty") Then MsgBox "Record replaced" Else MsgBox "record added" End If MsgBox MyCollection.Count If RecordExits(111, "site 1", "New Name") Then MsgBox "Record replaced" Else MsgBox "record added" End If MsgBox MyCollection.Count If RecordExits(222, "site 2", "Liss") Then MsgBox "Record replaced" Else MsgBox "record added" End If MsgBox MyCollection.Count For intIndex = 1 To MyCollection.Count Debug.Print MyCollection.Item(intIndex) Next End Sub Public Function RecordExits(CustomerID As Long, SiteName As String, ContactName As String) As Boolean Const SEPERATOR = ";" ' Use whatever seperator that would NEVER be in your ' data. You may need to validate the input beforehand ' to make sure it's not present On Error Resume Next ' Try to add the record MyCollection.Add CustomerID & SEPERATOR & SiteName & SEPERATOR & ContactName, CStr(CustomerID) If Err = 0 Then ' OK, it's added RecordExits = False Else RecordExits = True ' Remove the old record MyCollection.Remove CStr(CustomerID) ' Add the updated record MyCollection.Add CustomerID & SEPERATOR & SiteName & SEPERATOR & ContactName, CStr(CustomerID) End If End Function
Marty
HASTE CUISINE
Fast French food.




However, if you are willing to parse a string later on when to want to read the data in the collection then you can do this. 
Reply With Quote