Results 1 to 9 of 9
  1. #1
    shenasiB is offline Novice
    Windows 11 Office 365
    Join Date
    Oct 2023
    Posts
    4

    split the imported text in access table

    Hello, I need you support to split the imported text in access table as follows.

    1st word: фсдффд дс дддд ддддДФ ФФФФ
    2nd word: 120-0000000007-55
    3rd word: -150.00 (as a number)


    4th word: 289 (as a number)
    5th word: џџџ га ггго xxxxx за yyyyyy
    6th word: 670000262-0217 and
    7th word: /

    The trim is not working in order to have only one space between the word probably due to converting of text in UNICODE UT8.

    Please for you assistance. Attached is the txt file and the table in access

    all the best

    Shenasi
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Unless they are always the same length, you are going to struggle?
    Plus you have not shown how the data is to start with?

    Quite important I would have thought?
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make a SPEC definition

    ---------------
    PREP
    ---------------
    1st, manually import the text file: New data source, From File, Text File,
    choose the file
    in the 'import screen' ,bottom left corner is ADVANCED
    define your fields in the text as an IMPORT SPEC.
    SAVE this spec. (i.e: "SpecName")


    use this spec name to import text files


    now you can make an append query to append the txtFile2Import fields to the target table.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I would Split() on whatever that character is between the data you require.
    Then loop through each element of the array and test for that character as Left(,1)
    If not that character then move the data to your field, keeping track of which number field it is.

    That is not going to work fully as you have that character in amongst the first set of data?
    That character is CHR(32)

    Edit:
    You might get away with replacing chr(32)*3 with chr(32)*2 until no more replacements.
    Then replace chr(32) & "-" with CHR(32) & CHR(32) & "-"

    Then split() by CHR(32) & CHR(32) and do what I first mentioned.
    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

  5. #5
    shenasiB is offline Novice
    Windows 11 Office 365
    Join Date
    Oct 2023
    Posts
    4
    thank you for this guidance, it seems is good to try it. The second line is not working, the error typo mismatch appeared. The space multiplied with 3 times is not allowed. The 3rd line is also not working. Please for further instructions?
    strPomosenString = UTF8_Decode(strRecDetail(5))
    strText = Replace(strPomosenString, Chr(32) * 3, Chr(32) * 2)
    strText = Replace(Chr(32) & "-", Chr(32) & Chr(32) & "-")

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No, that was me showing how many characters you need.
    In the replace you would have chr(32)&chr32)&chr(32) and the same with the two chr(32) characters.
    You will need to loop that replace of 3 for 2 until no replacement occurs, so you will need to assign the replace to another variable and compare to the first variable, then move the data and replace again until they are the same.
    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

  7. #7
    shenasiB is offline Novice
    Windows 11 Office 365
    Join Date
    Oct 2023
    Posts
    4
    thank you. Perfect, I came to one space between each word. Now what is further instruction to treat all the 5 words as one word "фсдффд дс дддд ддддДФ ФФФФ" because some time there are 4 or 6 words until to next word which is 120-0000000007-55, the 3rd word is easy because has all has sign of minus. The 5th word will be solved same as the first word.



  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No, my idea was you need two chr(32) between each element of data.
    One Chr(32) is not going to cut it, that is why I suggested two.

    I was curious to see if I could do it, so you are lucky, normally I would not do this, unless it interested me.

    Code:
    Sub SpliText(pstrString As String)
    Dim i As Integer, iLen As Integer, iNewLen As Integer
    Dim strAField() As String
    
    
    iLen = Len(pstrString)
    
    
    Do Until iLen = iNewLen
        iLen = Len(pstrString)
        pstrString = Replace(pstrString, Chr(32) & Chr(32) & Chr(32), Chr(32) & Chr(32))
        iNewLen = Len(pstrString)
    Loop
    pstrString = Replace(pstrString, Chr(32) & "-", Chr(32) & Chr(32) & "-")
    strAField = Split(pstrString, Chr(32) & Chr(32))
    For i = 0 To UBound(strAField)
        Debug.Print strAField(i)
    Next
    
    
    
    
    End Sub
    Code:
    splitext("?????? ?? ???? ?????? ????                                             120-0000000007-55 -150.00            289   ??? ?? ???? xxxxx ?? yyyyyy         670000262-0217          /")
    Result, allowing for I do not have those characters.
    Code:
    ?????? ?? ???? ?????? ????
    120-0000000007-55
    -150.00
    289
    ??? ?? ???? xxxxx ?? yyyyyy
    670000262-0217
    /
    You will need to use the Val() function on those numeric fields as Split() returns a string.

    However that should get you almost there?
    NB: I have just used Debug.Print to confirm the array contents. Up to you to use them correctly.
    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

  9. #9
    shenasiB is offline Novice
    Windows 11 Office 365
    Join Date
    Oct 2023
    Posts
    4
    thank you very much. The code is working perfectly.

    It is very appreciated.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-21-2019, 04:58 PM
  2. Replies: 10
    Last Post: 03-16-2018, 12:28 AM
  3. Replies: 2
    Last Post: 12-17-2015, 11:41 AM
  4. Replies: 1
    Last Post: 10-30-2014, 06:31 AM
  5. Replies: 3
    Last Post: 04-20-2012, 04:33 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