Results 1 to 3 of 3
  1. #1
    worldwidewall is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    23

    Seek Method


    I am running Access 2003.

    I want to use the seek method to search for a record in a table. I need to match multiple criteria. Can someone show me the vba code?

    Thanks

    Dave

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,628
    Never used Seek. This article says need to use an array to pass a set of values to KeyValues argument: http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

    It doesn't show building the array but the variable varKeyValues in the Sub is the variable receiving the array.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Just a note - the seek does not work with linked tables, in case you are using them.

    First, create a compound index in the table, using the fields you will be using to do the search.

    Then, in VBA:

    dim rst as Recordset

    set rst = Currentdb.Openrecordset("MyTable")
    rst.index = "IndexName" (This can be "Primarykey" if the PK of the table is compound, and that is what you are using)

    Then, let's say you used two fields for the index you created. To search for a record, you would use:

    rst.seek "=", Value1, Value2
    if not rst.nomatch then
    '
    ' Do this is a record WAS found
    '
    else
    '
    ' Do this if a record WAS NOT found
    '
    endif

    Where Value1 and Value2 are the values you are looking for - they don't have to be numeric, strings are OK. "IndexName" is the name you gave to the index when you created it.

    HTH

    John


    I know that you don't have to use "="; the other operators work too - but I never use them. Check the help file for details.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. GetUser method
    By pkstormy in forum Code Repository
    Replies: 7
    Last Post: 11-22-2012, 06:00 PM
  2. tryparse method
    By mejia.j88 in forum Programming
    Replies: 5
    Last Post: 02-27-2012, 01:57 PM
  3. Question about best method
    By tdanko128 in forum Programming
    Replies: 2
    Last Post: 01-30-2011, 01:41 PM
  4. Class Method
    By AndreT in forum Programming
    Replies: 3
    Last Post: 01-20-2011, 02:18 AM
  5. Which method is better?
    By undrcvr in forum Database Design
    Replies: 3
    Last Post: 05-24-2010, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums