Results 1 to 5 of 5
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Is this a bug in Access


    Code:
    Dim strTestString As String
    Dim I As Integer
    
    I = 1
    
    strTestString = "HdText" & Str(I)
    
    strTestString = "HdText" & Trim(Str(I))
    The first setting of strTestString results in "HdText 1" while the second results with the desired string "HdText1". What's with the leading blank returned from the "Str" function?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    From help on Str():

    When numbers are converted to strings, a leading space is always reserved for the sign of number. If number is positive, the returned string contains a leading space and the plus sign is implied.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks. Funny all the times I've used the Str function it hasn't been with a string concatenation.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. I'd typically just do:

    strTestString = "HdText" & I
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Now that you mention what you do typically I'm reminded that that is what I've done in the past myself. The current app development is peppered with string data so I had my "string" hat on when I coded the concatenation the first time and then spent 20 minutes chasing the resulting bug in Debug where the unwanted "blank" was inserted.

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

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