Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Good afternoon (EST)
    I found an article and code sample I am trying to run: How to retrieve the selected items in a multiple selection list box as a comma delimited string in microsot Access . I am running access 2003 sp3 on windows 7.

    Following the example provided I get an error when opening the form: Run time error 2465 - "Access can't find the field myselections referred to in your expression" . I have a text box per the example named mySelections on my form.

    The code is:
    Private Sub Form_Current()
    Dim oItem As Variant
    Dim bFound As Boolean
    Dim sTemp As String
    Dim sValue As String
    Dim sChar As String
    Dim iCount As Integer
    Dim iListItemsCount As Integer

    sTemp = Nz(Me!mySelections.Value, " ")
    iListItemsCount = 0
    bFound = False
    iCount = 0

    Call clearListBox

    For iCount = 1 To Len(sTemp) + 1
    sChar = Mid(sTemp, iCount, 1)
    If StrComp(sChar, ",") = 0 Or iCount = Len(sTemp) + 1 Then
    bFound = False
    Do
    If StrComp(Trim(Me!NamesList.ItemData(iListItemsCount )), Trim(sValue)) = 0 Then
    Me!NamesList.Selected(iListItemsCount) = True
    bFound = True
    End If
    iListItemsCount = iListItemsCount + 1
    Loop Until bFound = True Or iListItemsCount = Me!NamesList.ListCount
    sValue = ""
    Else
    sValue = sValue & sChar
    End If
    Next iCount
    End Sub

    I have searched on found remedies ranging from reinstalling sp3, turning off name auto correct, and of course confirming the text box is named properly. I continue to get the error. Is this a common error and are there any other suggestions for troubleshooting this?
    Thank you for your help!

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by spburke View Post
    ....Run time error 2465 - "Access can't find the field myselections referred to in your expression" . I have a text box per the example named mySelections on my form.....
    Sounds like one of your references is to myselections and not to mySelections (which is what the code calls for). HTH
    Gre

  3. #3
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Salem, Oregon, USA
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, just for starters, I wouldn't put it in an "on current" module, because -- won't you want someone to be able to make a selection, first? Unless I'm not understanding what you are trying to do.

    So -- have you put a breakpoint before the line: "sTemp = Nz(Me!mySelections.Value, " ")" to make sure it's choking there (and, is this the multi-select list field which will probably be null in the "on-current" event?)

    I would start by moving the code to a button, and then just double-check the name you gave the field.

    Pat

  4. #4
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Not quite sure what you are trying to do here but
    Assuming you have a list box with text items in it and Multi Select set as single
    Also are you trying to collect the selected items in a multi select lisy box into standard Delimited list,
    or read a delimited list and select multiple items in a list box

    If the Former, then have a look at the code example below

    It collects the data from a list box called lstnames that are selected
    and writes the list into a comma separated list
    The example just uses variables, and generates a list and also the delimeted list

    Nothing like yours but might help

    Code:
    Dim strItem As String, strDelim As String, strTextQual As String, strList As String, strItems As String
    Dim varItem
    
    'Set Defaults and also Delimiter and Text Qualifier
    strItems = ""
    strItem = ""
    strDelim = ","
    strTextQual = Chr(34)
    strList = ""
    
    'Check there are selected Items
    If lstNames.ItemsSelected.Count <> 0 Then
        'Loop through all selected Items
        For Each varItem In lstNames.ItemsSelected
            strItem = lstNames.ItemData(varItem)
            'If First then Build First Item Otherwise Append to Variable
            If strList = "" Then
                strList = strTextQual & strItem & strTextQual & strDelim
            Else
                strList = strList & strTextQual & strItem & strTextQual & strDelim
            End If
            strItems = strItems & strItem & vbLf
        Next
        'Crop Last delimiter off the list
        strList = Left(strList, Len(strList) - 1)
    End If
    
    'Message box with Items as list and also as delimited list
    MsgBox "Delimeted List From " & vbLf & strItems & vbLf & strList, vbExclamation
    Andrew

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Quote Originally Posted by Patricia W View Post
    Well, just for starters, I wouldn't put it in an "on current" module,
    This example actually does more than just retreive the values in the multiselct list box. It puts these in the textbox which is bound to a field in the table.
    So the job of the On Current event is to look at what is already in this field, and display this in the listbox.

    There is separate code in a button that retrive the listbox selections and puts that back in the textbox.
    Regards
    John



  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I attach a little demo that uses the microsoft code unchanged. Does this generate the same error for you?

    [attachment=87925:Multiselect.zip]
    Attached Files Attached Files
    Regards
    John



  7. #7
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by John Hutchison View Post
    I attach a little demo that uses the microsoft code unchanged. Does this generate the same error for you?

    [attachment=87925:Multiselect.zip]
    John, all,
    Thank you once again for the help. Your demo did work. I started over and was able to get the code to work with the microsoft example. In my first attempt I deleted and recreated the text box (myselections) which might have broken the reference. I scrapped it, started over, and now its working. User error. Thank you all for your help. Glad to get it working.

Posting Permissions

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