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