+ Reply to Thread
Results 1 to 12 of 12

Trailing Characters/Space when querying via ADODB.recordset getrows

  1. #1
    Registered User
    Join Date
    08-05-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Trailing Characters/Space when querying via ADODB.recordset getrows

    Hi,

    I'm getting a problem whereby the data that I'm querying from a mySQL based database has a trailing spaces/characters.

    E.g.

    Data stored

    User Number 1 Number 2
    ---------------------------------
    "Joel" , "5" , "-5"


    Data retrieved

    "Joel " , " 5 " , " -5 "


    I've tried using trim, and it works for the numbers but it doesn't work for the string, as it's a unrecognized character hence it doesn't get trimmed as it's not a space.

    Anybody knows what is going on here?

    Thanks!

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    1) Are you very sure the data stored does not contain that extra blank space character (for the string field)?
    2) Since you posted in this Excel VBA forum, are you transferring the data into an Excel sheet?
    3) If you are sure for (1), and the space always exists after extracting, and if you are putting the data into a worksheet, you can use a formula to remove trailing character using the formula: =LEFT(A1,LEN(A1)-1)
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    This formula will tell you what it is 32 is a regular space and 160 a non-breaking space. TRIM doesnot work with those.

    =substitute(A1,CHAR(160),"")

    does work...
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  4. #4
    Registered User
    Join Date
    08-05-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    I've realised that using varchar data type instead of text data type in the mysql DB is causing the extra spaces/characters in the user field. However as it is also a primary key that I'm querying, I can't have it as a text, it must be a char, can anyone suggest what can be done about this?

    Also what can I do about the numeric fields?

    Thanks!

  5. #5
    Registered User
    Join Date
    08-05-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    Quote Originally Posted by millz View Post
    1) Are you very sure the data stored does not contain that extra blank space character (for the string field)?
    2) Since you posted in this Excel VBA forum, are you transferring the data into an Excel sheet?
    3) If you are sure for (1), and the space always exists after extracting, and if you are putting the data into a worksheet, you can use a formula to remove trailing character using the formula: =LEFT(A1,LEN(A1)-1)
    I'm absolutely certain the stored data has no extra space/characters.
    I'm using Excel VBA to pull the data into a spreadsheet, but I need to compare it first hence the query.

  6. #6
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    Then you can use VBA code to remove the extra character(s) first before comparing:
    Please Login or Register  to view this content.
    or as suggested by Glenn,
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-05-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    Seems like I can't address the fundamental issue of having a extra character,

    I'll just have to remove the characters as they get produced.

    Okay, thanks guys!

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    My post at #3 was a bit cryptic, as the formula disappearred.

    =CODE(RIGHT(A1,1))

    What value do you get... 32, or 160, or what

  9. #9
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    Quote Originally Posted by Jay-T View Post
    Seems like I can't address the fundamental issue of having a extra character,
    Well, I am not familiar enough with mySQL to know where the problem lies exactly. It could be the database or field setting, it could be the connection type, it could be ... I don't know

    Don't remember facing such issues when querying MSSQL/Access databases though.

  10. #10
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Get rows New Line carriage return Wonks Line feed.. Lateral Thinking. vbCR vbLf

    Get rows New Line carriage return Wonks Line feed.. Lateral Thinking. vbCR vbLf


    Hi I am coming in very late here, but this thread just helped me solve a similar mystery that I had had.
    ( and the Thread is not marked as Solved , and i am adding...a solution.. in a lateral thinking sort of a way )

    My Problem:

    I was developing a code to remove code lines.
    This required checking the first Character in the code line to see if it was a number.

    For example, I copy the three code lines 10 , 20 , 30 below to the Clipboard ( Highlight those three lines and Hit Ctrl+C )
    Please Login or Register  to view this content.
    Then I run my code to remove code lines, for example they start like the demo code below:

    In My code below, section Rem 1) , takes the String text held in the Clipboard and '1 c) puts it in an Array , arrCodlnsIn1() ( - '1 c) uses the VBA Strings function Split to split the String from the Clipboard by the carriage return vbCr )
    '1 d) checked out the first character. I expected that line 200 to catch “1” “2” and “3” . But I caught just “1” in the first loop. After that I caught what “looked” like “ “

    This is what the I see in the watch window: – _...
    LfSpace.JPG
    http://imgur.com/rQN3qCN
    Attachment 482239

    _...you “see” extra spaces before “ 20” and “ 30”. But I am guessing that that is the interpretation of what the “thing” is.. (_... often an obscure Chr( ) may be present in a string and what we “see” may come out in whatever form the particular thing we use to look at it interprets it.
    http://www.mrexcel.com/forum/excel-q...ml#post4214083 _....
    ..)


    _..................................

    After reading this thread I modified a version of my code to produce the demo code for this post
    Line 220 shows me nothing in cell A1 for what I see in the watch window as “ “
    In line 230 I sandwich the “thing” between a couple of pipes , | | , and display that in the immediate Window. I see in the Immediate Window this

    |
    |


    Still not getting too far. But then from this thread I caught the Code( ) idea.

    Line 240 in my code below cracked it for me. It returns the value of 10. Looking up an ASCII Table tells me that is a new line. Then I thought .. New Line, sounds like Line Feed.

    Rem 2 ) Has another go at splitting the text string with a carriage return and a line feed, vbCr & vbLf

    Bingo ! ( three times ! ) - So my mysterious character was a line Feed.

    I am only just now trying to get clued up with “SQL’s and ADODB.recordset stuff”, but I believe it has a lot to do with interpreting data that gets chucked at you in a long text “stream”
    Clearly if you are “getting rows” then various chr( ) are included staring from the end of the first row. My problem similarly to the OP’s started at the end of the first data and /or start of the second, which amounts to the same thing I suppose.

    Once I found out what the character was, the solution was clear. I am not sure how that translates to the OP problem. But some lateral thinking base on my experience might suggest another idea, but I cannot think of anything just now.

    Alan


    P.s. Just for fun My demo code Rem 3). I split by just a vbLF. I “see” in the Immediate window at the end of the first two “rows” a “space” “thing” which is not there.
    CrSpace.JPG
    http://imgur.com/5i1IpMR
    Attachment 482240

    Surprise, surprise, Line 420 in my demo code gives ASCII character 13 – a Carriage Return, vbCr



    Demo code:

    Please Login or Register  to view this content.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  11. #11
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    FYI, you can do Split function with vbCrLf

  12. #12
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: Trailing Characters/Space when querying via ADODB.recordset getrows

    Thanks.
    I had noticed that, I assume it is identical to vbCr & vbLf. I notice now that a lot of people use vbCrLf. Previously I had used vbCr for no particular reason and " got away with it".
    I guess vbCrLf could be a good default choice.
    I find it good though to delve in a bit and "see" what is actually "there”
    Were you able to reveal what character was giving you problems?
    Alan
    Last edited by Doc.AElstein; 09-28-2016 at 03:27 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Change ADODB.Recordset by New
    By Remphan in forum Access Tables & Databases
    Replies: 1
    Last Post: 03-13-2016, 07:51 PM
  2. [SOLVED] Comparing Variant Array to ADODB.Recordset?
    By mc84excel in forum Access Tables & Databases
    Replies: 2
    Last Post: 09-14-2015, 07:29 PM
  3. Refresh ADODB Recordset
    By oteixeira in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-01-2011, 04:12 AM
  4. Check if equal: Cells with adodb recordset
    By Huija in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-09-2008, 01:25 AM
  5. [SOLVED] ADODB.Recordset from workbooks : numbers only?
    By JVLin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2006, 12:00 AM
  6. writing ADODB recordset to excel sheet
    By bhavesh78 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2005, 12:55 PM
  7. [SOLVED] Delete ADODB Recordset
    By Jim Thomlinson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2005, 01:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1