Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2019
    Posts
    1,103

    Username function works (in general) but includes "weird characters" when used in a concat string

    Good morning:

    I need some assistance with, potentially, cleaning up/trimming a string value (i.e., "strPath_2").

    Recap (username):
    - DB includes a "username" import function.
    - There never has been any issues displaying it when using "username" in, e.g., a form's text field.

    Recap (what I'm trying to achieve):


    - I need to create an export routine that outputs, e.g., a spreadsheet on the user's name desktop (or any other designated path)
    - To make it dynamic, I'd like to create a concatenated file path string

    Issue:
    - Per VBA code below, the username ("strPath_2") returns a bunch of block/rectangle characters
    - Thus, when concatenating all 3 string elements (i.e., "strPath_Concat = strPath_1 & strPath_2 & strPath_3"), the third element ("strPath_3") is NOT included in the concatenated string ("strPath_Concat").

    Goal:
    - Output, e.g., "strPath_Concat" = "C:\Users\jsmith\CompanyName\Mainfolder\Subfolder" .... where "jsmith" is NOT a constant but being dynamically read into


    Please see attached PNG which illustrates both the 'hover over' values as well as 'message boxes'. If indeed strPath_2's block/rectangle characters cause strPath_3 NOT to be included in the concatenated string, what is the solution for, e.g., trimming/cleaning up "strPath_2"?

    Code:
    Option Compare Database
    Option Explicit
        
    Private Sub Form_Load()
    
        'Checks current network login ID is
        Me!txtNetworkID = fOSUserName()
        Me!txt_username = Me!txtNetworkID
              
    End Sub
    
    
    
    
    Private Sub Listbox1_AfterUpdate()
    
        Dim strPath_1 As String
        Dim strPath_2 As String
        Dim strPath_3 As String
        Dim strPath_Concat As String
    
    
        strPath_1 = "C:\Users\"
        strPath_2 = Me!txtNetworkID
        strPath_3 = "\CompanyName\Mainfolder\Subfolder"
    
    
        strPath_Concat = strPath_1 & strPath_2 & strPath_3
        
        
        MsgBox "Msg Box #1: " & strPath_1
        MsgBox "Msg Box #2: " & strPath_2
        MsgBox "Msg Box #3: " & strPath_3
        MsgBox "Msg Box Concat: " & strPath_Concat    
        
            
        '... More functionality
        '...
        '...
    
    
    End Sub
    Attached Thumbnails Attached Thumbnails HoverOver_MsgBoxes.png  

  2. #2
    Join Date
    Feb 2019
    Posts
    1,103

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Hi Tom,
    Do you still get those characters if you use the function directly in the str_Path2 assignment? Could it be that the first textbox (NetworkID) adds the padding?
    Code:
    str_Path2=fOSUserName()
    Here are a couple alternatives to get you to the desktop:
    https://www.devhut.net/vba-getting-t...ystem-folders/
    https://excel.tips.net/T008233_Findi...oogle_vignette
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 11
    Last Post: 08-27-2019, 07:25 PM
  2. Replies: 1
    Last Post: 01-18-2019, 06:32 AM
  3. Replies: 3
    Last Post: 01-06-2016, 01:18 PM
  4. Concat a string that already has "&" in it.
    By jscriptor09 in forum Programming
    Replies: 1
    Last Post: 02-07-2013, 01:15 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