Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with seek method

Status
Not open for further replies.

aradia926

MIS
Jul 11, 2005
29
US
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
 
Hello

Create a Multiple PK in the "segments" table like this:
Index Name Field Name Properties
"IDX" 1st Field Primary, Unique, Not Null
2nd Field

You should write as this:
Set inds = db.OpenRecordset("Segments", dbOpenTable)
inds.index = "IDX"
inds.Seek "=", 1st Field, 2nd Field

this time it works...
Try and let me know.
Bye
Fabio
 

Thanks Fabio!

Sorry I did not get back sooner.

I tried what you suggested, but it is not working for me. I think I might need to be a little bit more clear about some of the details of my database.

I have 3 fields in my table. They are:

NEW_REC_NO (PK, Duplicates OK, Not Null)
Segment (PK, Duplicates OK, Not Null)
REC_NO (Duplicates OK, Not Required)

I need to use the Seek method on the last field (REC_NO), searching for the value stored in the variable intselfacnum. I don't see how I could make this field a primary key.

Hopefully this makes it a little easier to visualize.

Thank you again for your help, I really appreciate it as I am totally lost.

Lori
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top