What is instead IN statement in VBA?

Ishim684

Registered User.
Local time
Tomorrow, 01:45
Joined
Oct 13, 2016
Messages
16
Dear Access experts, excuse me if my question is very simple, but I am entirely new to VBA.

I need to write an IF... Then... Else statement where the conditions run the check whether a certain value is found in a table. Something like:

If strString is IN [tblTable]![Field] Then

But there is no IN statement in VBA.

What is the common practice for executing such kinds of tasks?
 
If the string is anywhere in the table? Depends on what your actual goal is, but I'd probably open a recordset on an SQL statement that found the desired record(s). Then test the recordset:

If Not rs.EOF Then

would indicate that the recordset found records mathing the criteria.
 
We use DCount for that. For example
Code:
If DCount("*", "[tblTable]", "[Field] = '" & strString & "'") > 0 Then

but if there is any chance strString could have a single quote in it, e.g., O'Malley then

Code:
If DCount("*", "[tblTable]", "[Field] = '" & Replace(strString, "'", "''") & "'") > 0 Then

Both assume [Field] is a text field.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom