Results 1 to 4 of 4
  1. #1
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23

    Extract Value from Variable in String

    Hi,

    I am trying to create function that extracts the value from a variable on a given string:

    For example
    ColumnA: PropertyLocation:Type=email,Medium=5,Name=campaign 1

    Result Goal:
    ColumnB(Type): email


    ColumnC(Medium): medium
    ColumnD(Name): campaign1

    I tried the following:

    Function sMedium(dummystring As String) As String
    Dim element As Variant
    For Each element In Split(url, ",")
    If Split(element, "=")(1) = "Medium" Then
    sMedium = Split(element, "=")(1)
    Exit Function

    Else
    sMedium = ""

    Next element

    End Function


    There seems to be a comple error. If there is another approach, I would be interest in knowing.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    Try:
    Code:
    Function sMedium(URL As String) As String
    Dim element As Variant, i As Integer
    element = Split(URL, "=")
    For i = 0 To UBound(element)
        If element(i) = "Medium" Then
            sMedium = element(i)
            Exit Function
        End If
    Next
    End Function
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nguyenak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    23
    Sorry, for clarification,
    Input: PropertyLocation:Type=email,Medium=5,Name=campaign 1


    Result Goal:
    ColumnB(Type): email
    ColumnC(Medium): 5
    ColumnD(Name): campaign1

    the above code didnt work.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    You are trying to parse the value into 3 pieces in a query? Use an argument for the function to know which piece to return. Try:
    Code:
    Function ParseString(sString As String, ColID As String) As String
    Dim element As Variant
    element = Split(sString, ",")
    Select Case ColID
        Case "B"
            ParseString = Mid(element(1),InStr(element(1),"=")+1)
        Case "C"
            ParseString = Mid(element(2),InStr(element(2),"=")+1)
        Case "D"
            ParseString = Mid(element(3),InStr(element(3),"=")+1)
    End Select
    End Function
    Then call the function:
    ParseString(input, "B")
    ParseString(input, "C")
    ParseString(input, "D")

    OR

    Code:
    Function ParseString(sString As String, ColID As Integer) As String
    Dim element As Variant
    element = Split(sString, ",")
    ParseString = Mid(element(ColID),InStr(element(ColID),"=")+1)
    End Function
    Then the function calls would be:
    ParseString(input, 0)
    ParseString(input, 1)
    ParseString(input, 2)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Extract String From Between 2 Values
    By kathleencampbell in forum Queries
    Replies: 5
    Last Post: 03-23-2012, 10:52 AM
  2. Convert Number to String in .csv extract
    By CindyR19 in forum Import/Export Data
    Replies: 3
    Last Post: 08-17-2011, 02:58 PM
  3. Replies: 1
    Last Post: 02-03-2011, 07:41 AM
  4. Using a string variable to specify a control
    By Gerry in forum Programming
    Replies: 3
    Last Post: 04-14-2010, 02:28 PM
  5. Extract numbers from text string strored in a field.
    By khabdullah in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 06:55 PM

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