Results 1 to 4 of 4
  1. #1
    esh112288 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    14

    Smile Taking variables from a string and turning them into strings


    I've got the following scenario:

    I'm using a multi-select box which has both a TypeID number and a TypeName for each selection
    Once the user selects multiple items, I have code which turns the TypeID numbers into a string with commas in between i.e. "2, 4, 8". These items are stored in one field of the main table as TEXT
    I'm looking to write a query to pull all of the numbers in between the commas and turn those numbers into their matching name.
    So "2, 4, 8" would become "Alpha, Delta, Beta".
    Last, I'm going to create a new "printable" form which displays this field with selections rather than the list box.

    Can someone help me to write the code/query for this? I'm no expert with VB and am not sure where to turn.

    Thanks.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have code which turns the TypeID numbers into a string with commas in between i.e. "2, 4, 8".
    I would use the same code, but instead of using the bound column (usually column 0), use the "Column" property, changing 0 to whatever column the text is in.

    control.Column(column, row)

  3. #3
    esh112288 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    14
    Quote Originally Posted by ssanfu View Post
    I would use the same code, but instead of using the bound column (usually column 0), use the "Column" property, changing 0 to whatever column the text is in.
    I definitely understand what you mean by displaying column 2 versus the ID column. However, I was able to reapply the code from someone else and the result was the first column and I can't determine how to change it based on what you've said. The following is what I have:

    Code:
    Private Sub QAList_Click()
     
    Dim SelectedValues As String
    Dim frm As Form
    Dim varItem As Variant
    Dim lstItems As Control
    Set lstItems = Me!QAList
     
    For Each varItem In lstItems.ItemsSelected
        If SelectedValues > "" Then
            SelectedValues = SelectedValues & ", " & lstItems.ItemData(varItem)
        Else
            SelectedValues = lstItems.ItemData(varItem)
        End If
    Next varItem
    Me!QAType = SelectedValues
     
    End Sub

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    How about this?
    Code:
    Private Sub QAList_Click()
    
       Dim SelectedValues As String
    '   Dim frm As Form
       Dim varItem As Variant
       Dim lstItems As Control
       Dim ListCol As Integer
    
       ListCol = 1
    
       Set lstItems = Me!QAList
       For Each varItem In lstItems.ItemsSelected
          If SelectedValues > "" Then
             SelectedValues = SelectedValues & ", " & lstItems.Column(ListCol, varItem)
          Else
             SelectedValues = lstItems.Column(ListCol, varItem)
          End If
       Next varItem
    
       Me!QAType = SelectedValues
    
    End Sub

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

Similar Threads

  1. Replies: 3
    Last Post: 04-23-2012, 12:06 AM
  2. turning a string into a date
    By imintrouble in forum Access
    Replies: 2
    Last Post: 09-30-2011, 02:25 PM
  3. Turning a cell red
    By Sharong in forum Access
    Replies: 3
    Last Post: 09-28-2011, 01:51 PM
  4. Turning a Value into a positive
    By swagger18 in forum Programming
    Replies: 7
    Last Post: 01-25-2011, 09:42 AM
  5. Query NOT taking the two parameters WHY?
    By iamraja5 in forum Forms
    Replies: 7
    Last Post: 03-16-2010, 04:29 AM

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