I have the following code which is used to select items in a list box:
Set tdf = db.TableDefs![Segments]
' Return Index object that points to new index.
Set idx = tdf.CreateIndex("REC_NO")
Set inds = db.OpenRecordset("Segments")
inds.Index = idx.Name
For x = 0 To [frmMain]!SegCombo.ListCount
[frmMain]!SegCombo.Selected(x) = True
Next x
For Each varitem In [frmMain]!SegCombo.itemsselected
If Not IsNull([frmMain]!SegCombo.ItemData(varitem)) Then
wscategory = [frmMain]!SegCombo.ItemData(varitem)
inds.Seek "=", intSelFacNum, wscategory
If inds.NoMatch Then [frmMain]!SegCombo.Selected(varitem) = False
End If
Next varitem
Where:
REC_NO is an Indexed field allowing duplicates, but is not the Primary Key
intSelFacNum is a global variant variable whose value is set in a different procedure but holds the REC_NO value I am looking for.
I get the run-time error 3250 "Could not create key" on the line highlighted above.
I guess I just don't understand the process of programmatically setting indexes and using the seek method. I have performed the same function on the primary key field in this table using similar code, and it worked fine.
Could someone take a look at my code for errors and/or explain what I might be doing wrong? Thanks!
Lori
Set tdf = db.TableDefs![Segments]
' Return Index object that points to new index.
Set idx = tdf.CreateIndex("REC_NO")
Set inds = db.OpenRecordset("Segments")
inds.Index = idx.Name
For x = 0 To [frmMain]!SegCombo.ListCount
[frmMain]!SegCombo.Selected(x) = True
Next x
For Each varitem In [frmMain]!SegCombo.itemsselected
If Not IsNull([frmMain]!SegCombo.ItemData(varitem)) Then
wscategory = [frmMain]!SegCombo.ItemData(varitem)
inds.Seek "=", intSelFacNum, wscategory
If inds.NoMatch Then [frmMain]!SegCombo.Selected(varitem) = False
End If
Next varitem
Where:
REC_NO is an Indexed field allowing duplicates, but is not the Primary Key
intSelFacNum is a global variant variable whose value is set in a different procedure but holds the REC_NO value I am looking for.
I get the run-time error 3250 "Could not create key" on the line highlighted above.
I guess I just don't understand the process of programmatically setting indexes and using the seek method. I have performed the same function on the primary key field in this table using similar code, and it worked fine.
Could someone take a look at my code for errors and/or explain what I might be doing wrong? Thanks!
Lori