Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    United Kingdom

    Unanswered: Looking for text within a field

    Hi guys,

    I need an AfterUpdate event on a form to look in the text entered in a field called "RECName" to see if the terms "LREC" or "MREC" appear within the text.

    If they do then I want it to "do nothing" and let the user carry on, but if they do not appear then I want to delete the text just entered and display a message box with a brief warning message.

    I've tried several different If statments but am not at all sure how to look for text anywhere within a field using VBA.

    Any help would be greatly appreciated (especially as it's Friday).


  2. #2
    Join Date
    Jun 2002
    Mpls/St.Paul area
    Try looking up the InStr function.

    Returns a Variant (Long) specifying the position of the first occurrence of one string within another.

    InStr([start, ]string1, string2[, compare])

    start Optional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains Null, an error occurs. The start argument is required if compare is specified.
    string1 Required. String expression being searched.
    string2 Required. String expression sought.

    The function returns a zero if it didn't find the string being sought.
    This is the day the Lord has made, I will rejoice and be glad in it.

  3. #3
    Join Date
    Jun 2004
    Or use this coding:

    Dim Response as String

    If RecName Like"*LRec*" Or RecName Like "*MRec*" Then
    Response = Msgbox( )
    End If

Posting Permissions

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