+ Reply to Thread
Results 1 to 6 of 6

Problem with listview click event.

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Problem with listview click event.

    Hi,

    I have a userform in which user can select multiple criteria and the final result is displayed in a Listview. Everything is working fine. I use Access as the database. For some records, some fields are blank. For that 'Not Available' is displayed.
    Problem is when the select criteria returns a record which having all the fields as 'Not Available' (which is displaying correctly in Listview), when user clicks on this item i'm getting error message 'Run Time Error 13 Type Mismatch'. Only the first field is in 'Number' data type. Completed my project almost but unable to submit due to this error. Below is my code:
    Private Sub CmdSearch_Click()
    ListView1.Enabled = True
    
    ListView1.ListItems.Clear
    
    For index = 0 To ListBox6.ListCount - 1
        If ListBox6.Selected(index) Then
            If IDList <> "" Then IDList = IDList & ", "
            IDList = IDList & "'" & Format(ListBox6.List(index), "000") & "'"
            End If
    Next
    SFList = IDList
    
    
    Call openConnection
        Set rs = New ADODB.Recordset
    If IDList <> "" Then
        
            rs.Open "SELECT Emp_ID, Name, Cell_Number, WithCountry_Code, Work_Business_No, Extension, Home_Number, vNet, eMail, BCM_Role, Designation, Ops_Sales_Cus_Loc, Remark_on_Facility FROM DL_Mapping where Region in (" & Rglist & ") and Country in (" & CList & ")and State in (" & StateList & ") and City in (" & CityList & ") and Facility in (" & FacList & ") and Support_Function in (" & SFList & ")", Con, 1, 2
            ListView1.ListItems.Clear
    
            If rs.RecordCount > 0 Then
                ListView1.ListItems.Clear
                rs.MoveFirst
                Do While rs.EOF = False
                    If IsNull(rs.Fields("Emp_ID")) Then
                        Set lvwItem = ListView1.ListItems.Add(, , "Not Available")
                    Else
                        Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Emp_ID").Value)
                    End If
                    If IsNull(rs.Fields("Name")) Then
                        lvwItem.SubItems(1) = "Not Available"
                    Else
                        lvwItem.SubItems(1) = rs!Name
                    End If
                    If IsNull(rs.Fields("Cell_Number")) Then
                    lvwItem.SubItems(2) = "Not Available"
                    Else
                    lvwItem.SubItems(2) = rs!Cell_Number
                    End If
                    If IsNull(rs.Fields("WithCountry_Code")) Then
                    lvwItem.SubItems(3) = "Not Available"
                    Else
                    lvwItem.SubItems(3) = rs!WithCountry_Code
                    End If
                    If IsNull(rs.Fields("Work_Business_No")) Then
                    lvwItem.SubItems(4) = "Not Available"
                    Else
                    lvwItem.SubItems(4) = rs!Work_Business_No
                    End If
                    If IsNull(rs.Fields("Extension")) Then
                    lvwItem.SubItems(5) = "Not Available"
                    Else
                    lvwItem.SubItems(5) = rs!Extension
                    End If
                    If IsNull(rs.Fields("Home_Number")) Then
                    lvwItem.SubItems(6) = "Not Available"
                    Else
                    lvwItem.SubItems(6) = rs!Home_Number
                    End If
                    If IsNull(rs.Fields("vNet")) Then
                    lvwItem.SubItems(7) = "Not Available"
                    Else
                    lvwItem.SubItems(7) = rs!vNet
                    End If
                    If IsNull(rs.Fields("eMail")) Then
                    lvwItem.SubItems(8) = "Not Available"
                    Else
                    lvwItem.SubItems(8) = rs!eMail
                    End If
                    If IsNull(rs.Fields("BCM_Role")) Then
                    lvwItem.SubItems(9) = "Not Available"
                    Else
                    lvwItem.SubItems(9) = rs!BCM_Role
                    End If
                    If IsNull(rs.Fields("Designation")) Then
                    lvwItem.SubItems(10) = "Not Available"
                    Else
                    lvwItem.SubItems(10) = rs!Designation
                    End If
                    If IsNull(rs.Fields("Ops_Sales_Cus_Loc")) Then
                    lvwItem.SubItems(11) = "Not Available"
                    Else
                    lvwItem.SubItems(11) = rs!Ops_Sales_Cus_Loc
                    End If
                    If IsNull(rs.Fields("Remark_on_Facility")) Then
                    lvwItem.SubItems(12) = "Not Available"
                    Else
                    lvwItem.SubItems(12) = rs!Remark_on_Facility
                    End If
    
                    
                    rs.MoveNext
                Loop
            Else
                ListView1.ListItems.Clear
            End If
    
        rs.Close
        Set rs = Nothing
        Con.Close
        
    IDList = ""
    End If
    End Sub
    
    Private Sub ListView1_Click()
    
      
            
        If Me.ListView1.SelectedItem >= 0 Then
        CommandButton10.Enabled = True
            With UserForm3
                .TextBox1.Value = ListView1.SelectedItem.Text
                .TextBox2.Value = ListView1.SelectedItem.SubItems(1)
                .TextBox3.Value = ListView1.SelectedItem.SubItems(2)
                .TextBox4.Value = ListView1.SelectedItem.SubItems(3)
                .TextBox5.Value = ListView1.SelectedItem.SubItems(4)
                .TextBox6.Value = ListView1.SelectedItem.SubItems(5)
                .TextBox7.Value = ListView1.SelectedItem.SubItems(6)
                .TextBox8.Value = ListView1.SelectedItem.SubItems(7)
                .TextBox9.Value = ListView1.SelectedItem.SubItems(8)
                .TextBox10.Value = ListView1.SelectedItem.SubItems(9)
                .TextBox11.Value = ListView1.SelectedItem.SubItems(10)
                .TextBox12.Value = ListView1.SelectedItem.SubItems(11)
                .TextBox13.Value = ListView1.SelectedItem.SubItems(12)
    
            End With
        Else
        MsgBox "No Selection Made"
        End If
    
    
    End Sub

    Kindly have a look and plz help me out. Thanks in advance.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problem with listview click event.

    which line causes the error?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Problem with listview click event.

    If Me.ListView1.SelectedItem >= 0 Then

    in the listview click event

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problem with listview click event.

    perhaps just change it to
    If Val(Me.ListView1.SelectedItem) >= 0 Then

  5. #5
    Registered User
    Join Date
    09-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Problem with listview click event.

    Hi JosephP,

    Its working.
    Thanks a ton.

    Regards,
    Kiran2012

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Problem with listview click event.

    you're welcome

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1