Type mismatch when loading data from db to listview
-
I am using VBA (Access 2007) for my project. On the form load, listview retrieves data from the db but gets problem (Error Message : Type mismatch). Here is my code. Dim Rst As New ADODB.Recordset Dim Str As String Rst.CursorLocation = adUseClient Str = "Select * From qry_staff_info Order By sID" Rst.Open Str, Application.CodeProject.Connection, adOpenDynamic If Rst.RecordCount < 0 Then Exit Sub If Rst.RecordCount > 0 Then Do While Not Rst.EOF Dim lvwItem As ListItem Set lvwItem = Me.lvwStaff.ListItems.Add(, , Rst![insurno]) ''''''' This the line which debug and show the error message (Type mismatch) lvwItem.SubItems(1) = Rst![sname] lvwItem.SubItems(2) = Rst![bgroup] lvwItem.SubItems(3) = Rst![gender] lvwItem.SubItems(4) = Rst![dob] lvwItem.SubItems(5) = Rst![doj] lvwItem.SubItems(6) = Rst![Position] lvwItem.SubItems(7) = Rst![location] lvwItem.SubItems(8) = Rst![Address] lvwItem.SubItems(9) = Rst![Telephone] lvwItem.SubItems(10) = Rst![martialstatus] lvwItem.SubItems(11) = Rst![nod] Loop End If Thanks,
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
I am using VBA (Access 2007) for my project. On the form load, listview retrieves data from the db but gets problem (Error Message : Type mismatch). Here is my code. Dim Rst As New ADODB.Recordset Dim Str As String Rst.CursorLocation = adUseClient Str = "Select * From qry_staff_info Order By sID" Rst.Open Str, Application.CodeProject.Connection, adOpenDynamic If Rst.RecordCount < 0 Then Exit Sub If Rst.RecordCount > 0 Then Do While Not Rst.EOF Dim lvwItem As ListItem Set lvwItem = Me.lvwStaff.ListItems.Add(, , Rst![insurno]) ''''''' This the line which debug and show the error message (Type mismatch) lvwItem.SubItems(1) = Rst![sname] lvwItem.SubItems(2) = Rst![bgroup] lvwItem.SubItems(3) = Rst![gender] lvwItem.SubItems(4) = Rst![dob] lvwItem.SubItems(5) = Rst![doj] lvwItem.SubItems(6) = Rst![Position] lvwItem.SubItems(7) = Rst![location] lvwItem.SubItems(8) = Rst![Address] lvwItem.SubItems(9) = Rst![Telephone] lvwItem.SubItems(10) = Rst![martialstatus] lvwItem.SubItems(11) = Rst![nod] Loop End If Thanks,
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
misCafe wrote:
(Error Message : Type mismatch)
Could that be caused by
insurno
being a number? Try converting it explicitly;Set lvwItem = Me.lvwStaff.ListItems.Add(, , CStr(Rst![insurno]))
I are Troll :suss:
Thanks so much for your help. The problem is fixed. :) Anyways, I want to click on the ListView Item and load its values from each colums to the TextBox, ComboBox. It is the better way to update the record.
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
Thanks so much for your help. The problem is fixed. :) Anyways, I want to click on the ListView Item and load its values from each colums to the TextBox, ComboBox. It is the better way to update the record.
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner