Results 1 to 6 of 6
  1. #1
    Whughes98 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Location
    Brunswick, GA
    Posts
    3

    Find Function and Return Value

    I am trying to write a query that looks within a field for a specific value and returns that value to me, but I can't figure out a formula to do it. The value is not is the same position for each row. Example below:

    Table: GL Detail
    Field: Modifiers


    Looking for value contained in the field = 'U1' Return the value as '1'

    Sample values in the field:

    U1:U7
    U1:U6
    GT:U6:U1
    GT:U1:U6

    Can anyone give me a formula or SQL script that would help me with this?

    Thanks
    Wendy

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    What exactly would be returned in these samples?
    U1:U7
    U1:U6
    GT:U6:U1
    GT:U1:U6

    Also, it is advisable to not use table or field names with embedded spaces.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Create a module

    Put this code in the module and save it

    Code:
    Public Function GetGLPosition(sFieldContents, sSearchString)Dim ArrayItems
    
    
    If InStr(sFieldContents, ":") Then
        ArrayItems = Split(sFieldContents, ":")
        For I = 0 To UBound(ArrayItems)
            If sSearchString = ArrayItems(I) Then
                GetGLPosition = I + 1
                Exit Function
            End If
        Next I
    Else
        If sSearchString = sFieldContents Then GetGLPosition = 1
    End If
    End Function
    in your query the syntax would be

    GLPosition: getglposition([Fieldname], "SearchString")

    so for instance if you were looking for the position of the string "U1" and your field name was called GLString you would use

    GLPosition: getglposition([GLString], "U1")

    Then you could add criteria for which glposition you were looking for (i.e. a criteria of 1 in the GLPosition field)

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    In a Query:
    x: IIf([Modifiers] Like '*U1*',1,0)

  5. #5
    RobFlott is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2015
    Posts
    22
    Thank you

  6. #6
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Not sure if its applicable here but FYI in Access True=-1 and False=0.

    Well... Technically anything <>0 is true but officially True=-1

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-29-2015, 04:49 PM
  2. Query to find condition and return field name
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 01-15-2014, 02:04 PM
  3. Replies: 3
    Last Post: 11-15-2012, 06:59 PM
  4. Function to return a set of records?
    By vicrauch in forum Access
    Replies: 2
    Last Post: 07-12-2011, 08:27 AM
  5. Replies: 1
    Last Post: 06-23-2010, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums