Results 1 to 4 of 4

Thread: getting value of selected items in listview

  1. #1

    Thread Starter
    Lively Member PatOls's Avatar
    Join Date
    Oct 2000
    Posts
    99

    Arrow

    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


  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    I think it's because you overwrite strsource in your
    For...Next

  3. #3
    Guest
    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).






  4. #4

    Thread Starter
    Lively Member PatOls's Avatar
    Join Date
    Oct 2000
    Posts
    99

    Wink thx

    thx man, that worked out nicely.....

    //Patrick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width