Can I do this?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table with a composite primary key ie.
I would normally do a seek like this:-

rstTgt.seek"=",key1,key2,key3
if not rstTgt.nomatch then
:
else
:
end if

Now then, can I do a search using only one known part of the multiple key
like:

rstTgt.seek">=",key1 ( or indeed any other key part)
if not rstTgt.nomatch then
:
else
:
end if

If not, what route should I consider, dlookup; findfirst etc.

Thanks


Jack
 
You can perform a ">=" seek on the first keys only, i.e. you cannot do it
without supplying at least key1.

Although the Seek method is very fast, I never use that approach any more.
It only works on a recordset of type dbOpenTable. That means it's useless if
you want multiple tables in your recordset, a filtered or sorted recordset,
and it fails when you split the database. You will want to split at some
point. If that's a new concept, see:
http://allenbrowne.com/ser-01.html

The better solution is to OpenRecordset on as few records and fields as
possible, sorted as desired. This example loads only the records matching
the values for Key1 and Key2, and all values of Key3, sorted the way this
primary key index works:
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "SELECT Table1.* FROM Table1 " & _
"WHERE (Key1 = 9) AND (Key2 = 99) " & _
"ORDER BY Key1, Key2, Key3;"
Set rs = dbEngine(0)(0).OpenRecordset(strSql)
 
Back
Top