Results 1 to 11 of 11
  1. #1
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    96

    Transform a memo field into columns


    I have copied some data from an online catalogue and have it in a memo field (one record)

    is it possible to transform the data into a single column by separating each text item by the space

    I have attached a pdf to show table and part of the meme field

    Thanks
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    What do you class as each text item?

    B4-94 xxxxxx
    or
    B4-94
    xxxxxx

    I would use Split() with the relevant divider. That is up to you.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    DaveT99 is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Mar 2018
    Location
    SPAIN
    Posts
    96
    Quote Originally Posted by Welshgasman View Post
    What do you class as each text item?

    B4-94 xxxxxx
    or
    B4-94
    xxxxxx

    I would use Split() with the relevant divider. That is up to you.

    tHE 2ND OPTION, ACTUALLY ONLY WANT THE xxxxxx VALUES BUT I GET ALL AS PER YOUR 2ND OPTION EASY TO GET RID OF THE UNWANTED

    IS split () IS THAT THE FIELD NAME TO GO INTO THE BRACKETS, E.G SPLIT (P/n)

    tHANKS
    dAVE

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,940
    You do this in vba

    Code:
    dim a() as string
    dim i as integer
     
    a=split(fieldname," ")
    for i=0 to ubound (a)
        debug. Print a(i) 
        ' do whatever here - add to a string, append to a table, etc
        i=i+1
    next i
    edit now on a computer so corrected

    step alternative
    Code:
    dim a() as string
    dim i as integer
     
    a=split(fieldname," ")
    for i=0 to ubound (a) step 2
        debug. Print a(i)
        ' do whatever here - add to a string, append to a table, etc
    
    next i

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Quote Originally Posted by DaveT99 View Post
    tHE 2ND OPTION, ACTUALLY ONLY WANT THE xxxxxx VALUES BUT I GET ALL AS PER YOUR 2ND OPTION EASY TO GET RID OF THE UNWANTED

    IS split () IS THAT THE FIELD NAME TO GO INTO THE BRACKETS, E.G SPLIT (P/n)

    tHANKS
    dAVE
    So I would use @CJ_London's logic, but loop from 1 and step 2

    He also meant UBound, not unbound
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,940
    oops - problem with doing the from a phone with autocorrect

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Quote Originally Posted by CJ_London View Post
    oops - problem with doing the from a phone with autocorrect
    I know, annoying as hell.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Join Date
    Sep 2025
    Location
    Newport, Shropshire, UK
    Posts
    25
    Quote Originally Posted by DaveT99 View Post
    ACTUALLY ONLY WANT THE xxxxxx VALUES
    In that case I'd include the constant B4-94 in the divider when calling the Split function. You can see how it works in the immediate window:

    Code:
    CatListing = "B4-94 12345 B4-94 23456 B4-94 34567 B4-94 45678 B4-94 56789"
    a = Split(CatListing,"B4-94 ")
    ? Trim(a(1))
    12345
    ? Trim(a(2))
    23456
    ? Trim(a(3))
    34567
    ? Trim(a(4))
    45678
    ? Trim(a(5))
    56789
    In reality you'd loop through a recordset based on your table, and for each row in the recordset loop through the array and insert each value into a row in a new referencing table, along with a foreign key value referencing the primary key of the current row in the recordset.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Not all B4-94 though Ken?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Join Date
    Sep 2025
    Location
    Newport, Shropshire, UK
    Posts
    25
    Quote Originally Posted by Welshgasman View Post
    Not all B4-94 though Ken?
    Doh! You're absolutely right. At 79 I'm having some difficulty reading the PDF image.

  11. #11
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    436
    you can save the p/n's to a table (table tblPN, with short text field PN).
    Code:
    Private Sub t()
    Dim db As DAO.Database
    Dim rsSource As DAO.Recordset
    Dim rsTarget As DAO.Recordset
    Dim pn$, i&, j&, var, p$
    Set db = CurrentDb
    ' open your Source table here
    Set rsSource = db.OpenRecordset("select [p/n] from Dodge;")
    ' open the table where you want to save (tblPN)
    Set rsTarget = db.OpenRecordset("tblPN")
    With rsSource
        If Not .EOF Then
            .MoveFirst
        End If
        Do Until .EOF
            pn = RTrim$(LTrim$(![p/n] & ""))
            ' remove extra space if there is
            Do While InStr(1, pn, "  ") <> 0
                ' replace double space with single space
                pn = Replace$(pn, "  ", " ")
            Loop
            ' loop until all alphanumeric is found
            var = Split(pn, " ")
            i = UBound(var)
            j = 0: p = ""
            Do While True
                If j > i Then
                    If Len(p) <> 0 Then
                        rsTarget.AddNew
                        rsTarget!pn = p
                        rsTarget.Update
                    End If
                    Exit Do
                End If
                p = p & " " & var(j)
                If IsNumeric(var(j)) Then
                    rsTarget.AddNew
                    rsTarget!pn = p
                    rsTarget.Update
                    p = ""
                End If
                j = j + 1
            Loop
            .MoveNext
        Loop
    End With
    rsSource.Close: rsTarget.Close
    Set rsSource = Nothing: Set rsTarget = Nothing: Set db = Nothing
    End Sub

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

Similar Threads

  1. transform zero values into null (blank)
    By mar7632 in forum Access
    Replies: 15
    Last Post: 03-11-2019, 02:41 AM
  2. Replies: 21
    Last Post: 08-19-2018, 02:38 AM
  3. Replies: 2
    Last Post: 04-22-2017, 04:31 PM
  4. Replies: 4
    Last Post: 10-17-2016, 06:19 PM
  5. Replies: 9
    Last Post: 07-21-2014, 11:57 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