I am not sure what exactly you want to do, but assume this is what you want to achieve:
1. Create a ODTable, either via code, or manually create one. So, the code works against a ODTable with known table name
2. For every entity in modelspace, you want to see if the entity has the OD record from that table already attached or not. If not, you want to attach the OD record from that table; if already attached, optinally, you may want to update the record's values.
Checking if an entity has a OD record with given table namke is where you need to call ODRecords.Init(), which retrieves all OD records attached to an entities (these records could be froom multiple ODTables).
Here is sample code that runs OK in my AutoCAD Map/Civil2017:
Option Explicit
Public Sub TestODTable()
Dim proj As AutocadMAP.Project
Dim table As AutocadMAP.ODTable
Dim acMap As AutocadMAP.AcadMap
Set acMap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
Set proj = acMap.Projects(0)
''MsgBox proj.ODTables.Count & " Table(s) found"
Set table = GetTargetTable("MY_OD_TABLE", proj)
If table Is Nothing Then
MsgBox "Object Data Table ""MY_OD_TABLE"" does not exist!"
Exit Sub
Else
MsgBox "Object Data Table ""MY_OD_TABLE"" found"
End If
'' attach od record to all entities in modelspace with default values
Dim ent As AcadEntity
For Each ent In ThisDrawing.ModelSpace
AttachOdRecord ent, table
Next
End Sub
Private Function GetTargetTable( _
tblName As String, proj As AutocadMAP.Project) As AutocadMAP.ODTable
Dim tbl As AutocadMAP.ODTable
For Each tbl In proj.ODTables
If UCase(tbl.Name) = UCase(tblName) Then
Set GetTargetTable = tbl
Exit Function
End If
Next
Set GetTargetTable = Nothing
End Function
Private Sub AttachOdRecord(ent As AcadEntity, tbl As AutocadMAP.ODTable)
Dim r As AutocadMAP.ODRecord
If Not HasTableRecord(ent, tbl) Then
Set r = tbl.CreateRecord()
r.AttachTo CLng(ent.ObjectID)
End If
End Sub
Private Function HasTableRecord(ent As AcadEntity, tbl As AutocadMAP.ODTable) As Boolean
Dim found As Boolean
Dim r As AutocadMAP.ODRecord
Dim rs As AutocadMAP.ODRecords
Set rs = tbl.GetODRecords()
If rs.Init(ent, False, True) Then
Do Until rs.IsDone
Set r = rs.Record
If UCase(r.tableName) = UCase(tbl.Name) Then
found = True
Exit Do
End If
rs.Next
Loop
End If
HasTableRecord = found
End Function
As you can see the code first verify the given table exists; then loop through each entity in modelspace to check if a record from that table is attached or not. If not, attach a record from that table. Pay attention to the function HasTableRecord(): This is where you are struggling. I think.
HTH