I am using a recordset as a vehicle for some data that I am acquiring. I am getting duplicates and I was curious as to how to get the recordset to complain if an attempt to add a duplicate is made.
So, essentially I want to create a key field. I have found the adFldKeyColumn parameter but it is not enforced, I must be missing something.
Function CreateIndexedRecordSet() As ADODB.Recordset
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Fields.Append "Name", adBSTR, 255
rs.Fields.Append "pkey", adInteger, , adFldKeyColumn
rs.Open
rs.AddNew Array("Name", "pkey"), Array("foo", 1)
rs.AddNew Array("Name", "pkey"), Array("bar", 1) '<--- this should complain
Debug.Print rs.Supports(CursorOptionEnum.adIndex) '<--- sadly prints False, perhaps use a different provider?
Set CreateIndexedRecordSet = rs
End Function
Please no triage answers, I know full well I can use a Dictionary whilst I acquire the data and catch duplicates that way, that is what I will do in the meantime. It's just there must be an ADO expert out there who knows the trick.
UPDATE: I have found a Supports method on the RecordSet object, if I pass in CursorOptionEnum.adIndex
then it replies False. Perhaps use a different provider?