Results 1 to 2 of 2

Thread: Someone help me fix this!!

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Someone help me fix this!!

    Sorry, this is an old post I figured out almost immediately, I tried to edit this before anyone saw it, so disregard the reply I got.

    Here is a sub I wrote for a listview's doubleclick event:

    VB Code:
    1. Private Sub lvwVolumeList_DblClick()
    2.     Dim a As String
    3.     Dim b As Long
    4.     Dim c As String
    5.     Dim lvw As ListView
    6.     Set lvw = lvwFileList
    7.     Set rs = New ADODB.Recordset
    8.     If lvw.ListItems.Count <> 0 Then lvw.ListItems.Clear
    9.     dtaBackups.RecordSource = "SELECT * FROM Files ORDER BY Container_Volume"
    10.     rs.Open dtaBackups.RecordSource, dtaBackups.ConnectionString, adOpenKeyset, adLockOptimistic
    11.     rs.MoveFirst
    12.     Do While Not rs.EOF
    13.         If Not rs!Container_Volume = lvwVolumeList.SelectedItem Then Exit Do
    14.         lvw.ListItems.Add , , rs!FileName
    15.         rs.MoveNext
    16.     Loop
    17.     For i = 1 To lvw.ListItems.Count
    18.         rs.MoveFirst
    19.         rs.Find "Filename = '" & lvw.ListItems(i) & "'", 0, adSearchForward
    20.         If rs.EOF = True Then
    21.             Exit For
    22.         Else
    23.             lvw.ListItems(i).SubItems(1) = rs!Size
    24.             lvw.ListItems(i).SubItems(2) = rs!DateTime
    25.         End If
    26.     Next i
    27.     rs.Close
    28.     Set lvw = Nothing
    29.     Set rs = Nothing
    30. End Sub

    This sub will only work when there's one item in the listview. When there's more than one, it only works for the last item. Why is this?
    Last edited by hothead; Sep 7th, 2003 at 06:54 PM.

  2. #2
    Addicted Member Cimperiali's Avatar
    Join Date
    Oct 2002
    Location
    Milan, Italy, Europe
    Posts
    188
    Code:
    Private Sub cmdCreateNewVolume_Click()
        Dim Response As String
        Dim bSkip As Boolean
        Do Until bSkip = True
          If cboMediumType.Text = "" Then Exit Sub
          Set rs = New ADODB.Recordset
          Response = InputBox("Enter volume name", "New Volume")
          SetMediaType
          rs.Open dtaBackups.RecordSource, dtaBackups.ConnectionString, adOpenKeyset, adLockOptimistic
          rs.Find "Volume_Name = '" & Response & "'", 0, adSearchForward
           
          If rs.EOF = True Then
              Set lstItem = lvwVolumeList.ListItems.Add(, , Response)
              lstItem.SubItems(1) = lvwFileList.ListItems.Count
              rs.AddNew
              rs!Volume_Name = lstItem.Text
              rs!Number_of_Files = lstItem.SubItems(1)
              rs.Update
              rs.Close
              dtaBackups.RecordSource = "SELECT * FROM Files ORDER BY Filename"
              rs.Open dtaBackups.RecordSource, dtaBackups.ConnectionString, adOpenKeyset, adLockOptimistic
              For i = 1 To lvwFileList.ListItems.Count
                  rs.AddNew
                  rs!Container_Volume = Response
                  rs!FileName = Replace(lvwFileList.ListItems(i), "'", "", 1, , vbTextCompare)
                  rs!Size = lvwFileList.ListItems(i).SubItems(1)
                  rs!DateTime = lvwFileList.ListItems(i).SubItems(2)
                  rs.Update
              Next i
              lvwFileList.ListItems.Clear
              cmdRenameSelectedVolume.Enabled = True
              cmdDeleteSelectedVolume.Enabled = True
              cmdRemoveSelected.Enabled = False
              cmdRemoveAll.Enabled = False
              Set lstItem = Nothing
              Set rs = Nothing
              'enough?
              bSkip = True
          Else
              MsgBox "A volume with that name already exists. Please enter another name.", vbExclamation, "Name already exists"
               
              'Exit Sub
          End If
      Loop
    End Sub
    Special thanks to some wonderful people,
    such as Lothar the Great Haensler, Aaron Young,
    dr_Michael, Chris Eastwood, TheOnlyOne ClearCode....

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