0

hello. how to do if when we double click at list view, then the information from list view will be appear at label. many times i tried but always debug (run time error '_2147217904(80040e10) 'no value given for one or more required parameter) .

Private Sub ListView1_DblClick()
checkConnection
strSql = "SELECT * FROM Schedule WHERE ReservationCode=" & ListView1.SelectedItem.Text & ""
rec1.Open strSql, con, adOpenStatic

lblReservationCode.Caption = rec1!ReservationCode
lblDestination.Caption = rec1!Destination
lblDate.Caption = rec1!Date
lblTime.Caption = rec1!Time
End Sub

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by choudhuryshouvi
0

always use ITEM_CLICK event of the LISTVIEW control to extract information of a specific item from the database.check out the following sample code. it uses an access database and connect through DAO.

before running this code create an access database "resv.mdb" and four fields which are "resv_code","dest","date","time" & also insert some records there.

take one LISTVIEW control & name it as "lvdetails". add four colume headers as "Reservation Code","Destination","Journey Date","Journey Time".
four LABELS and name them "lblresv_code","lbldest","lbldate" and "lbltime" accordingly.

**********IN FORM_LOAD EVENT********
'extracting all records from the database and displaying those in a lv control.

Dim db As Database
Dim rs As Recordset
Dim li As ListItem

Set db = OpenDatabase(App.Path & "\resv.mdb")
Set rs = db.OpenRecordset("details", dbOpenTable)

If rs.RecordCount > 0 Then
rs.MoveFirst
While Not rs.EOF()
With lvdetails
Set li = .ListItems.Add(, , rs!resv_code)
li.SubItems(1) = rs!dest
li.SubItems(2) = Format(rs!Date, "MMM-dd-yyyy")
li.SubItems(3) = Format(rs!Time, "hh:mm:ss")
End With
rs.MoveNext
Wend
End If
Set rs = Nothing

********IN ITEM_CLICK EVENT OF THE LISTVIEW CONTROL************
'clicking an item will extract it's specific information fom the database and display those in the labels.

Private Sub lvdetails_ItemClick(ByVal Item As MSComctlLib.ListItem)
Dim db As Database
Dim rs As Recordset

Set db = OpenDatabase(App.Path & "\resv.mdb")
Set rs = db.OpenRecordset("select * from details where resv_code='" & Item.Text & "'")
If rs.RecordCount > 0 Then
lbldate.Caption = IIf(IsNull(rs!Date), "", rs!Date)
lbldest.Caption = IIf(IsNull(rs!dest), "", rs!dest)
lblresvcode.Caption = IIf(IsNull(rs!resv_code), "", rs!resv_code)
lbltime.Caption = IIf(IsNull(rs!Time), "", rs!Time)
End If
Set rs = Nothing
End Sub


hope you will grab some idea from this sample. if require any more help post it in the same thread.

regards,
Shouvik

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.