Results 1 to 12 of 12
  1. #1
    JRodko is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    127

    Change Listbox Separating Character

    I have a listbox in a form that is doing nearly exactly what I want it to do. When I click into the datasheet style field I can select whatever options I want from a linked lookup table and they are being stored properly in the forms record source. Is there any way to change the separating character from a "," to a ";"?



    For example when my list box shows up I can select from the colours, I choose "Red", "Green", "Blue".

    When I go to the table where form data is stored that field is displayed as "Red, Green, Blue" which is mostly correct. Is there any way to change this to "Red;Green;Blue"?

    This is because I often export as CSV so obviously having a comma in there will ruin those exports.

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You are using a multi-value field? No, cannot change separator. A multi-value field really just stores pointers to records of a hidden dependent table. Access controls this, you cannot change how Access manages this link.

    I NEVER use multi-value field.

    Have you tried exporting this field type?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    JRodko is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    127
    Hi June7,

    It exports fine to .xlsx, CSV exports will be a mess. I don't think the table field is a multi-value field? I can't find anything in the properties sheet that says that it is, just a regular old short text field.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If it is multi-value the field will be formatted in table with a combobox (or I suppose a listbox but usually combobox) and AllowMultipleValues will be set to Yes.

    If not, then there must be some code that is concatenating selected values into a CSV string and that code can use whatever separator you want.

    I just tested a normal listbox on form with AllowMultipleSelect set to Yes but not associated with a multi-value field and it does not allow multiple selection in Datasheet view.

    I think you have a multi-value field.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    JRodko is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    127
    It appears that you are correct. How do you suggest I re-create this without a multi value field but one that concatenates from a set of options?

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Im assuming your using a multi-select listbox. I use the function below with multi-select list boxes. One of the arguments sets the seperator character in the string. You would call it with something like
    Code:
    X = getLBX(Me.MyListBoxName,1,";")

    Code:
    Public Function getLBX(lbx As ListBox, Optional intColumn As Variant = 0, Optional Seperator As String = ",", _
                           Optional Delim As Variant = Null) As String
    
    
    'Iterates thru the multiselect listbox and constructs an array of the selected items
    'Arguments:
    'Lbx is Listbox Object ie.Me.MyListbox
    'intColumn is the column # to be returned
    'Seperator is the character seperating items in array returned
    'Delim is optional delimiter to be return in array ie. #1/1/2001#,#12/25/2015#
    
    
        Dim strList As String
        Dim varSelected As Variant
    
    
        'On Error GoTo getLBX_Error
    
    
        If lbx.ItemsSelected.Count = 0 Then
            'MsgBox "Nothing selected"
        Else
    
    
            For Each varSelected In lbx.ItemsSelected
    
    
                If Nz(lbx.Column(intColumn, (varSelected)), "") <> "" Then
    
    
                    strList = strList & Delim & lbx.Column(intColumn, (varSelected)) & Delim & Seperator
    
    
                Else
    
    
                    strList = strList
    
    
                End If
    
    
            Next varSelected
    
    
            If Nz(strList, "") <> "" Then
    
    
                strList = Left$(strList, Len(strList) - 1)  'remove trailing comma
    
    
            End If
        End If
    
    
        getLBX = strList
    
    
        On Error GoTo 0
        Exit Function
    
    
    getLBX_Error:
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getLBX of Module modLBX"
    
    
    End Function

  7. #7
    JRodko is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    127
    Thank you moke123. I think that is a little bit beyond me. I will try to make this work.

    The data needs to be stored in 'Header! Probe_Serial' and the listbox is from another table named 'LKT_Probes! strProbes'

    I will have to try to implement this. I can create public functions etc. but the syntax of making this work eludes me.

    Cheers.

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Suggest you post a copy of your database (zip format) so readers can "see" what you are dealing with.
    We just need enough records to showcase the issue you are having.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You won't be able to use a Datasheet form. Use Continuous form.

    You will likely have to delete the multi-value field and create a new text field. Then use code suggested by moke to save CSV string into this field.

    Is 'Header! Probe_Serial' name of this field?

    Okay, driving me nuts - correct spelling is 'separator'
    Last edited by June7; 09-17-2019 at 02:12 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Okay, driving me nuts - correct spelling is 'separator'
    No spell check in the vbe and it's not something option explicit catches.
    At least now I know how to push your buttons

  11. #11
    JRodko is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    127
    I'm going to have to put more time into how I want to solve this. I generally use datasheet forms but for this situation I may need to have a separate continuous form or convert to continuous form.

    Thanks for the input. I will respond with further questions or with my solution.

  12. #12
    JRodko is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    127
    I am marking this thread as solved for my purposes. I ended up coming to the conclusion that the juice is not worth the squeeze. My total possible number of selections is actually fairly few (less than 10 combinations) so I have manually created them in my lookup table, and I have changed my listbox to a single select combo box.

    My solution is a little bit bush league but it also simplifies things and works well enough.

    Thanks!

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

Similar Threads

  1. Replies: 15
    Last Post: 01-23-2019, 11:44 AM
  2. Replies: 18
    Last Post: 10-11-2017, 03:07 PM
  3. Change query to populate listbox
    By AmanKaur123 in forum Queries
    Replies: 2
    Last Post: 05-06-2017, 02:43 AM
  4. Replies: 1
    Last Post: 05-05-2017, 02:32 AM
  5. Replies: 1
    Last Post: 12-15-2013, 08:10 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