How can I open a DataReport by clicking on ListView Item which loaded from a Recordset ?
Printable View
How can I open a DataReport by clicking on ListView Item which loaded from a Recordset ?
Moved To Reporting
I am waiting a solution.
I still wait.
Something like this.
Code:Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
If Not ListView1.SelectedItem Is Nothing Then
DataReport1.Show 1
End If
End Sub
Yes, thank you.
But I need to return a value from ListView to open DataReport by it.
I use this code with DataGrid for same purpose:
VB Code:
'============================== Private Sub DataGrid_DblClick() '============================== On Error GoTo Null_Click Dim RSReport As ADODB.Recordset Set RSReport = New ADODB.Recordset Dim SQL As String SQL = "SELECT * FROM mytable " SQL = SQL & " WHERE id LIKE '" & Trim(DataGrid.Columns(0).Value) & "'" SQL = SQL & " ORDER BY id ASC;" If RSReport.State = adStateOpen Then RSReport.Close RSReport.Open SQL, DB, adOpenStatic, adLockOptimistic If RSReport.RecordCount > 0 Then Set DataReport1.DataSource = RSReport DataReport1.WindowState = 2 DataReport1.Orientation = rptOrientPortrait DataReport1.Show , Me Else MsgBox " There is no results. " End If SQL = "" Null_Click: Exit Sub End Sub
I am looking for someting like this:
http://www.vbforums.com/showthread.php?t=532391
You've got the code already, you just have to modify it with something like this.
Code:Private Sub listview1_DblClick()
On Error GoTo Null_Click
Dim RSReport As ADODB.Recordset
Set RSReport = New ADODB.Recordset
Dim SQL As String
SQL = "SELECT * FROM mytable "
SQL = SQL & " WHERE id LIKE '" & Trim(listview1.SelectedItem.Text) & "'"
SQL = SQL & " ORDER BY id ASC;"
If RSReport.State = adStateOpen Then RSReport.Close
RSReport.Open SQL, DB, adOpenStatic, adLockOptimistic
If RSReport.RecordCount > 0 Then
Set DataReport1.DataSource = RSReport
DataReport1.WindowState = 2
DataReport1.Orientation = rptOrientPortrait
DataReport1.Show , Me
Else
MsgBox " There is no results. "
End If
SQL = ""
Null_Click:
Exit Sub
End Sub
Thank you.
But I need to get the first value (first column) from selected row in ListView, it's an ID number.
I got it with DataGrid by:I just want to apply the same way but with ListView.VB Code:
DataGrid.Columns(0).Value
.SelectedItem.Text should give you that, have you tried it? .SelectedItem is the selected row and the .Text is the first column.