-
Hey ya'll,
I'm trying this code for :
when user selects multiple rows in a listview and then wants them printed on one printout! (that's the idea anyhow!)
code :
Dim X As Object
Dim i As Integer
Dim db As Database
Dim rs As Recordset
Dim vaOsTime As String
Dim vaOsDate As String
vaOsTime = Time
vaOsDate = Date
If ListView1.SelectedItem Is Nothing Then Exit Sub
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Selected = True Then
Dim strSource, strCaption, strText As String
Dim strFooker As String
Dim strDBName As String
Dim strPepp0, strPepp2, strPepp3
strDBName = DBPath()
strFooker = ListView1.ListItems(i).SubItems(1)
strSource = "SELECT * FROM Class4 WHERE Detalj
LIKE '" & strFooker & "'"
End If
Next i
ActiveClassView.DAODataControl1.DatabaseName = strDBName
ActiveClassView.DAODataControl1.RecordSource = strSource
ActiveClassView.Label14 = Date
ActiveClassView.Label15 = Time
ActiveClassView.Printer.Orientation = ddOLandscape
ActiveClassView.Show
Users only get the first row selected printed, can anyone help me to get all rows selected printed?
//Patrick
-
I think it's because you overwrite strsource in your
For...Next
-
PatOls,
Try changing your For...Next loop as follows:
Code:
Dim strSource, strCaption, strText As String
Dim strFooker As String
Dim strDBName As String
Dim strPepp0, strPepp2, strPepp3
strFooker=""
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Selected = True Then
If Len(strFooker)<>0 Then
strFooker = strFooker & " OR "
End If
strFooker = strFooker & "LIKE '" & ListView1.ListItems(i).SubItems(1)
End If
Next i
strDBName = DBPath()
strSource = "SELECT * FROM Class4 WHERE Detalj " & strFooker
Also, it's never a good idea for put Dim statements
anywhere other than at the beginning of a Sub or Function
unless you have a very good reason for doing so (as far
as I can tell, there will only be a good reason for doing
so when VB.Net ships because VB.Net will support Block
scope for variables defined within a Do, For, or such like).
:D
-
thx
thx man, that worked out nicely.....
//Patrick