Page 4 of 4 FirstFirst 1234
Results 46 to 56 of 56
  1. #46
    darkwind is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2017
    Location
    Central U.S.
    Posts
    48
    Quote Originally Posted by skydivetom View Post
    Darkwind:

    thank you for the continued assistance. I appreciate it.

    Ok, I added the rs.Close line but now get a different error (3144). Am I still missing something else?
    Same bug, different implementation... we need a conditional so the trim query is only executed when there's something to trim...

    Code:
        Dim bTrimData As Boolean
    
    ...
    
                         If fld.Type = dbText Then
                            sSQLCreateTable = sSQLCreateTable & " WITH COMPRESSION,"
                            sSQLTrimData = sSQLTrimData & "[" & fld.Name & "] = Trim([" & fld.Name & "]),"
                            bTrimData = True
                         Else
    
    ...
    
                   'Trim
                   If bTrimData Then
                      Debug.Print sSQLTrimData
                      db.Execute sSQLTrimData, dbFailOnError
                      bTrimData = False
                   End If

    Quote Originally Posted by moke123 View Post
    Not to muddy the waters, but I'm curious as to the bloat created by creating and deleting the tables.

    I would normally be importing the data to a temp table in a temp database and then clean it up when appending to my real tables.


    When done I then delete the temp database.
    Yeah, deleting and recreating a ton of tables this way is suboptimal, at the least. I would certainly run a compact/repair once done with a big batch of this kind of thing. Overall this solution is fairly messy. If it were my project, I would just fix my original data import to construct the requisite tables WITH COMPRESSION before initial import and split out the date/time in the process. That would mean just creating the tables once, no need for this copy/trim/delete. But that's technically out-of-scope of the request... and at the time I started looking into this thread, I wasn't even aware these were imported tables to begin with.

  2. #47
    Join Date
    Feb 2019
    Posts
    1,046
    Moke123:

    That's exactly what we're doing here:
    1. [tbl_One] and [tbl_Two] are the *temp* tables into which data is imported.
    2. Darkwind's TRIM function performs the cleanup and
    3. Creates the new/real tables...
    4. Lastly, temp tables are deleted and real tables are renamed.

    From my perspective, the previous version (my actual app has a different table naming convention), it works BRILLIANTLY.

    The only issue we're now dealing with is the creation of "milli-seconds". Well, the process already creates the real tables with milli-seconds.

    Now, we're just left w/ the "cleanup".

  3. #48
    Join Date
    Feb 2019
    Posts
    1,046
    darkwind:

    Sorry, you lost me on your last post wrt the " bTrimData = True" and the next Trim lines.

    Kindly request to post the entire DB. Is it working for you now?

    Thank you,
    Tom

  4. #49
    darkwind is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2017
    Location
    Central U.S.
    Posts
    48
    Here's the full file.
    Attached Files Attached Files

  5. #50
    Join Date
    Feb 2019
    Posts
    1,046
    Darkwind:

    This last solution is BRILLIANT!!! Thank you sooo very, very much for assisting me in this one.

    I'll review the code in more detail and attempt to add some comments for the high-level procedures.

    Again, thanks!!!

    Tom

  6. #51
    Join Date
    Feb 2019
    Posts
    1,046
    @Darkwind:

    In one of your previous posts, you mentioned there was an issue (that you noticed) w/ the erroneous hh:nn:ss:mls of, e.g., 24:54:30:949.

    In the latest version, when running the TRIM function, this issue now makes the function fail. It's NOT your function but unclean data on my end.

    I have posted a new thread pertaining to identifying a solution which would clean the erroneous data BEFORE executing the TRIM function.

    https://www.accessforums.net/showthr...401#post502401

    'Thought you might be interested given you have familiarity w/ the function and the underlying data issue. Thanks!

  7. #52
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Please forgive me if I missed something but, I think that this thread would not have been created if, in the data entry routine of OP, the VARCHAR data type had been used instead of CHAR.
    Nevertheless, it was an occasion to learn something more and become wiser.

    Tom,

    Did you try to run the import routine with VARCHAR data type?

    Code:
    Sub ImportFiles(myDir)
    
        ...
                    For i = 0 To UBound(y)
                        s = s & IIf(s <> "", ", ", "") & "[FIELD" & i + 1 & "] VARCHAR(80)"
                    Next
    
        ...
        
    End Sub
    In my case, using VARCHAR in place of CHAR, the created tables appears with the data trimmed. So, no need to farther trimming and "magic" properties/technics.

  8. #53
    Join Date
    Feb 2019
    Posts
    1,046
    John:

    thanks for chiming in. Upon the data import, the date/time + milliseconds are stored as text. Not only does the TRIM function removes the trailing characters, it also converts the text string (date/time + milli-secs) into date format + numeric format (for calculations).

    So, @Darkwind's function accomplished both... removal of the trailing spaces and conversion into fields for calculation purposes.

    As indicated, the only issue occurs when the raw data (for some reason) was entered/created erroneously. Thus, it brings me back to the new thread that I opened where invalided hh:nn need to be converted into the next day.

    Hopefully I didn't misread your comment.

    Thanks,
    Tom

  9. #54
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Hopefully I didn't misread your comment.
    I think what AccessTOS and Darkwind are trying to say is that you should probably look back at your original import procedure
    and avoid all the bandaids.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  10. #55
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by moke123 View Post
    I think what AccessTOS and Darkwind are trying to say is that you should probably look back at your original import procedure
    and avoid all the bandaids.
    Exactly!

    I think that accidentally have been used the CHAR datatype at the beginning from the creator of the import procedure. Changing the CHAR data type to VARCHAR renders any later TRIM procedure useless. Moreover, CHAR data type provides fixed-length text fields. That's why the fixed length of 80 in all records. You can't trim a CHAR datatype field!

    I don't want to belittle anyone's effort. I just want to say that, generally, when a solution leads to more problems than it solves, it is good to reconsider the solution.

  11. #56
    Join Date
    Feb 2019
    Posts
    1,046
    Moke123 & John:

    thank you for the additional, valuable information. It the problem persists, I will to have investigate another method. For now though, Darkwind's function does do the trimming and milli-seconds extraction.

    Thanks,
    EEH

Page 4 of 4 FirstFirst 1234
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-01-2021, 05:30 PM
  2. Replies: 1
    Last Post: 04-12-2017, 07:39 AM
  3. Trim space between fields
    By rbolton in forum Forms
    Replies: 6
    Last Post: 04-14-2014, 08:33 PM
  4. Trim!
    By redbull in forum Programming
    Replies: 9
    Last Post: 11-06-2012, 06:01 AM
  5. Trim value
    By dada in forum Programming
    Replies: 5
    Last Post: 09-02-2010, 11:01 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