Yes, stIns will contain the value of field INS1 for the first row of the
recordset (and since you don't have an ORDER BY clause on the SQL, that
means it's essentially going to be a random value. Of course, I don't see
where you've instantiated rs anywhere.
Not only that, but you're trying to assign the results of the DLookup to a
string variable. If nothing's found, DLookup returns Null, and string
variables cannot be assigned a value of Null: the only data type that
accepts Null is the variant.
However, the DLookup itself doesn't look right.
The three arguments for Dlookup are supposed to be strings, which means that
you either use a string variable that's been assigned a value, or you put
the value in quotes.
You said you want to look at a field and see whether a value existed in the
table. Assuming you have a particular value, you'd use something like:
If DCount("*", "NameOfTable", "NameOfField = " & _
VariableHoldingValue) = 0 Then
MsgBox VariableHoldingValue & " is not in the table"
Else
MsgBox VariableHoldingValue & " is in the table"
End If
assuming that NameOfField is a numeric field, or
If DCount("*", "NameOfTable", "NameOfField = """ & _
VariableHoldingValue & """") = 0 Then
MsgBox VariableHoldingValue & " is not in the table"
Else
MsgBox VariableHoldingValue & " is in the table"
End If
if it's text.