Results 1 to 2 of 2
  1. #1
    REAbernathy is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    46

    Run-Time Error '2147417848(80010108) Method 'ItemData' of Object'_ListBox'Failed

    I need some assistance......I am getting this Run-Time Error Method 'ItemData of Object' _ListBox' Failed what I am doing wrong? Here is a copy of my code and also should the code be under Sub Form1 or Option Compare Database/Option Explicit? Again I am new to this world of VBA.Here is my code...Any Assistance would be greatly appericated.

    Private Sub Form_Current()
    Dim oItem As Variant
    Dim oItem1 As Variant
    Dim bFound As Boolean
    Dim sTemp As String
    Dim sTemp1 As String
    Dim sValue As String
    Dim sChar As String
    Dim iCount As Integer
    Dim iCount1 As Integer
    Dim iListItemsCount As Long
    Dim iListItemsCount1 As Long

    sTemp = Nz(Me!ErrorCodeDescriptionList88.Value, ";")
    sTemp1 = Nz(Me!ErrorCodesandCorrections.Value, ";")
    iListItemsCount = 0
    iListItemsCount1 = 0
    bFound = False
    iCount = 0
    iCount1 = 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!ErrorCodeDescriptionList88.ItemDat a(iListItemsCount)), Trim(sValue)) = 0 Then
    Me!ErrorCodeDescriptionList88.Selected(iListItemsC ount) = True
    bFound = True
    End If
    iListItemsCount = iListItemsCount + 1
    Loop Until bFound = True Or iListItemsCount = Me!ErrorCodeDescriptionList88.ListCount
    sValue = ";"
    Else
    sValue = sValue & sChar
    End If
    Next iCount

    For iCount1 = 1 To Len(sTemp1) + 1
    sChar = Mid(sTemp1, iCount1, 1)
    If StrComp(sChar, ";") = 0 Or iCount1 = Len(sTemp) + 1 Then
    bFound = False
    Do
    If StrComp(Trim(Me!ErrorCodesandCorrections.ItemData( iListItemsCount)), Trim(sValue)) = 0 Then
    Me!ErrorCodesandCorrections.Selected(iListItemsCou nt) = True
    bFound = True
    End If
    iListItemsCount1 = iListItemsCount1 + 1
    Loop Until bFound = True Or iListItemsCount1 = Me!ErrorCodesandCorrections.ListCount
    sValue = ";"
    Else
    sValue = sValue & sChar
    End If
    Next iCount1
    End Sub
    Private Sub ClearListBox()
    Dim iCount As Integer
    Dim iCount1 As Integer

    For iCount = 0 To Me!ErrorCodeDescriptionList88.ListCount
    Me!ErrorCodeDescriptionList88.Selected(iCount) = False
    Next iCount

    For iCount1 = 0 To Me!ErrorCodesandCorrectionsList.ListCount
    Me!ErrorCodesandCorrectionsList.Selected(iCount1) = False
    Next iCount1
    End Sub
    Private Sub Save_Record_Click()
    Dim oItem As Variant
    Dim oItem1 As Variant
    Dim sTemp As String
    Dim sTemp1 As String
    Dim iCount As Integer
    Dim iCount1 As Integer

    iCount = 0
    If Me!ErrorCodeDescriptionList88.ItemsSelected.Count <> 0 Then
    For Each oItem In Me!ErrorCodeDescriptionList88.ItemsSelected
    If iCount = 0 Then
    sTemp = sTemp & Me!ErrorCodeDescriptionList88.ItemData(oItem)
    iCount = iCount + 1
    Else


    sTemp = sTemp & ";" & Me!ErrorCodeDescriptionList88.ItemData(oItem)
    iCount = iCount + 1
    End If
    Next oItem
    Else
    MsgBox "Nothing was selected from the list", vbInformation
    Exit Sub 'Nothing was selected
    End If

    iCount1 = 0
    If Me!ErrorCodesandCorrectionsList.ItemsSelected.Coun t <> 0 Then
    For Each oItem1 In Me!ErrorCodesandCorrectionsList.ItemsSelected
    If iCount1 = 0 Then
    sTemp1 = sTemp & Me!ErrorCodesandCorrectionsList.ItemData(oItem)
    iCount1 = iCount1 + 1
    Else
    sTemp1 = sTemp1 & ";" & Me!ErrorCodesandCorrectionsList.ItemData(oItem)
    iCount1 = iCount1 + 1
    End If
    Next oItem1
    Else
    MsgBox "Nothing was selected from the list", vbInformation
    Exit Sub 'Nothing was selected
    End If

    Me!ErrorCodeDescription.Value = sTemp
    Me!ErrorCodesandCorrectionsList.Value = sTemp1


    End Sub
    Private Sub clrList_Click()
    Call ClearListBox
    Me!ErrorCodeDescription.Value = Null
    Me!ErrorCodesandCorrections.Value = Null
    End Sub
    Attached Files Attached Files

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't have A2K7, so I couldn't open your dB. I have no idea what you are trying to do, so I made a form and a couple of list boxes to test your code. I put the code behind a button so I could run it when I wanted. This is what I found so far.

    What are your list box names????
    --------------------------------
    In the sub Form_Current(), you have two list boxes named "ErrorCodeDescriptionList88" and "ErrorCodesandCorrections"

    In the subs Sub ClearListBox(), you have two list boxes named "ErrorCodeDescriptionList88" and "ErrorCodesandCorrectionsList"

    In the sub Sub Save_Record_Click(), you have two list boxes named "ErrorCodeDescriptionList88" and "ErrorCodesandCorrectionsList"

    In the sub Sub clrList_Click(), you have two list boxes named "ErrorCodeDescription" and "ErrorCodesandCorrections"


    In the sub Form_Current(), it looks like the list boxes are multi-select (because this of Me!ErrorCodeDescriptionList88.ItemData(iListItemsC ount))
    Walking through the code, these two variables have a semi-colon:
    Code:
       sTemp = nz(Me!ErrorCodeDescriptionList88.Value, ";")
       sTemp1 = nz(Me!ErrorCodesandCorrections.Value, ";")
    If the list boxes are multi-select, you cannot get the values this way.


    Next there is a line:
    Code:
    Call ClearListBox
    The list boxes are cleared of any selections before any other code uses the list boxes... ??


    Next:
    Code:
    If StrComp(Trim(Me!ErrorCodeDescriptionList88.ItemData(iListItemsCount)), Trim(sValue)) = 0 Then
    The variable "sValue" is not initalized, so it is NULL. Comparing a NULL with anything (including NULL) results in a NULL. So "NULL = 0" is FALSE.
    And there are no items selected because of the call to "ClearListBox".


    Then the Do - Loop....The first time through the the DO loop is OK.
    The second time it goes into an endless look because "bFound" is never TRUE and "iListItemsCount" doesn't get reset - it keeps increasing. It starts off greater than Me!ErrorCodeDescriptionList88.ListCount.
    Code:
    Loop Until bFound = True Or iListItemsCount = Me!ErrorCodeDescriptionList88.ListCount
    (this might be the cause of the error message)

    That is as far as I got with the code.
    --------------------------------------------------

    These two lines should be at the top of every code page:
    Code:
    Option Compare Database
    Option Explicit
    -----
    should the code be under Sub Form1
    I wouldn't think so. But I don't know what the purpose of the code is for.

    -----
    If you use (in A2K3) the dot (Me.) notation instead of the bang (Me!), the compiler catches undeclared variables (if Option Explicit is at the top of the page).

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

Similar Threads

  1. Replies: 1
    Last Post: 07-13-2012, 07:58 PM
  2. Replies: 4
    Last Post: 01-27-2012, 02:16 AM
  3. Method InsideHeight of object PlotArea failed
    By dgardineer in forum Programming
    Replies: 1
    Last Post: 10-26-2011, 01:52 PM
  4. Replies: 7
    Last Post: 02-03-2011, 07:13 AM
  5. Replies: 2
    Last Post: 02-28-2009, 03:31 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