Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    18

    Unanswered: Run-Time Error '2147417848 (80010108)

    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
    Last edited by Reabernathy; 08-03-12 at 14:13. Reason: Where the Error is showing

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    I did not checked the whole procedure, however the ItemData property begins at zero for the first item in the list, while the ListCount property begins at one. So, if a ListBox only has one line, it's ListCount property equals 1 and you can retrieve the value stored in its bound column using ItemData(0).
    Have a nice day!

Posting Permissions

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