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
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
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.
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.