Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Puts a single field from a recordset in a collection
- 'Parameters: rs: the recordset, Valname: The name or position of the field, KeyName (optional): the name or position of the field you want to use as keys in the collection
- 'Usage: Set MyCollection = RSToColl(MyRS, "Field1")
- Public Function RSToColl(rs As DAO.Recordset, Optional ValName As Variant = 0, Optional KeyName As Variant = Null) As VBA.Collection
- Dim coll As New VBA.Collection
- If Not rs.EOF Or rs.RecordCount > 0 Then rs.MoveFirst
- Do While Not rs.EOF
- If IsNull(KeyName) Then
- coll.Add rs.Fields(ValName).Value
- Else
- coll.Add rs.Fields(ValName).Value, rs.Fields(KeyName).Value & ""
- End If
- rs.MoveNext
- Loop
- Set RSToColl = coll
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement