Seek Method for Multiple-field index

B

Bill Herrick

I'm adding records to a table from a text file and need to verify that
records from this file don't already exist in the table. Insurance against
multiple imports.

A multiple-field index named EERecordIndex (strEEId, strJCID, ShortWrkDate,
intDataType - an employee can work on one job on one date) exists and I'm
trying to use it for comparison, but the rec.Seek code throws a 3019 error -
Operation invalid without a current index.

The code I'm using follows. What am I doing wrong?

Dim db As DAO.Database
Dim rec As DAO.Recordset

Set db = CurrentDb()
Set rec = db.OpenRecordset("tblPRDailyEarnTrans", dbOpenTable)
rec.Index = EERecordIndex

With rec

rec.Seek "=", strEEId, strJCID, ShortWrkDate, intDTP (strEEId, strJCID,
ShortWrkDate, intDTP are the input field names)

If rec.NoMatch Then
process the update
else
don't
end if

end with
 
D

Dirk Goldgar

Bill Herrick said:
I'm adding records to a table from a text file and need to verify that
records from this file don't already exist in the table. Insurance against
multiple imports.

A multiple-field index named EERecordIndex (strEEId, strJCID,
ShortWrkDate,
intDataType - an employee can work on one job on one date) exists and I'm
trying to use it for comparison, but the rec.Seek code throws a 3019
error -
Operation invalid without a current index.

The code I'm using follows. What am I doing wrong?

Dim db As DAO.Database
Dim rec As DAO.Recordset

Set db = CurrentDb()
Set rec = db.OpenRecordset("tblPRDailyEarnTrans", dbOpenTable)
rec.Index = EERecordIndex

With rec

rec.Seek "=", strEEId, strJCID, ShortWrkDate, intDTP (strEEId,
strJCID,
ShortWrkDate, intDTP are the input field names)

If rec.NoMatch Then
process the update
else
don't
end if

end with


Unless you've defined a string variable or constant named "EERecordIndex", I
think this line:
rec.Index = EERecordIndex

.... should be:

rec.Index = "EERecordIndex"

That is, the name of the index should be specified as a string. Do you have
Option Explicit set, to catch the use of undefined variables?
 
B

Bill Herrick

The index variable definition was the problem. I was so concerned with the
method I neglected the obvious. Thanks very much for the quick response.

Option Explicit is set and quotes are in place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top