check for records satisfying a criteria

M

Mark Kubicki

this should be simple (but, obviously, not yet in my vocabulary of code)

I simply want to check if a table [Table1] with fields [Field1,2,3...]
contains a record where [Field1] = Var1, AND [Field2] = Var2...

A simple Y/N responce is all that is required.

thanks in advance,
mark
 
K

KARL DEWEY

SELECT *
FROM [Table1]
WHERE [Field1] = Var1 AND [Field2] = Var2 ...AND [Field9] = Var9;
This will pull the records where you have a match in all fields.
If you want to find records that A field has a match then use this --
SELECT *
FROM [Table1]
WHERE [Field1] = Var1 OR [Field2] = Var2 ...OR [Field9] = Var9;
 
G

George Nicholson

Dim x as Long

' assuming Field1 is a numeric field and Field2 is text:
x = DCount("[Field1]","[Table1]","[Field1] = " & Var1 & " AND [Field2] = '"
& Var2 & "' AND ...etc...")

If x = 0 Then
msgbox "No matching records"
Else
Msgbox x & " matching records"
End If
 

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