Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2014

    Unanswered: Use "IF" statement to find single instance of text

    I'm fairly new to this - and learning every day. My dilemma is that I want to use something (macro?) to create an "IF" statement that reads a field in a table, and if a specific instance of text is found in any record, then continue with the IF/THEN condition.

    From a business standpoint, I want to use an IF condition to see if TABLE A has the value "Elk Lighting" in any of the records in the field "Brand". If the condition is true, continue on with running other queries (to clear tables, etc). I'm concerned that my IF statement was to run now, every instance of "Elk Lighting" would kick off the "clear this table" query.

    I can't find a way to do this, and could really use your help. Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 15
    In VBA, you can use the DCount() domain function:
    If DCount("*", "TableName" ,"Brand = 'Elk Lighting'") > 0 Then
        ' At least one row has the value "Elk Lighting" in the "Brand" column.
        ' No match.
    End If
    In SQL, you would use the Count Function:
    SELECT COUNT(*) FROM TableName WHERE Brand = 'Elk Lighting';
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts