• Run time 2465 Error with Multi select text box

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Run time 2465 Error with Multi select text box

    Author
    Topic
    #466132

    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!

    Viewing 3 reply threads
    Author
    Replies
    • #1206689

      ….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

    • #1206691

      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

      • #1206701

        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.

    • #1206699

      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
      
      
    • #1206703

      I attach a little demo that uses the microsoft code unchanged. Does this generate the same error for you?

      • #1206781

        I attach a little demo that uses the microsoft code unchanged. Does this generate the same error for you?

        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.

    Viewing 3 reply threads
    Reply To: Run time 2465 Error with Multi select text box

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: