Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Location
    paris, FRANCE
    Posts
    88

    Question Unanswered: parsing query parametering

    hello,
    I have a query based on a module which parses a memo field and which searches through this field for the word "Keywords:". The module code goes like this:

    Public Function TheKeyWords(longText As String) As String
    TheKeyWords = Mid$(longText, InStr(1, longText, "Keywords:") + 9)

    End Function

    My problem is that when the function doesn't find the value "Keywords:" it returns the full field.
    I'd like to add a IF loop to this code which states that if "Keywords:" is not found, the function should return an empty field.
    Can someone tell me how to do this?
    Thank you for your help.
    nico

  2. #2
    Join Date
    May 2002
    Location
    London
    Posts
    87
    Instr returns 0 if it doen't find the search string so
    Code:
    Public Function TheKeyWords(longText As String) As String
    Dim varPos As Variant
    varPos = InStr(1, longText, "Keywords:")
    If varPos >0 then
        TheKeyWords = Mid$(longText, InStr(1, longText, lngPos ) + 9)
    Else
        TheKeyWords = ""
    End If
    End Function
    Or whatever else you want to return.

    I've used a variant for the position as Instr can return null.

  3. #3
    Join Date
    Apr 2003
    Location
    paris, FRANCE
    Posts
    88

    Thumbs up

    Hey risky!
    your solution works fine thanks a lot!!!!
    nico

Posting Permissions

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