dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Need little help to void repeating msgbox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    612

    Resolved [RESOLVED] Need little help to void repeating msgbox

    Hi all
    I'm deleting multiple records from access database through listview.
    Code:
    For I = lvw.ListItems.Count To 1 Step -1
     If lvw.ListItems.Item(I).Checked = True Then
    Dim Msg As String
    Msg = MsgBox("Voulez Vous vraiment supprimer ce dossier?", vbQuestion Or vbYesNo)
    If Msg = vbYes Then
    StrSql = "delete * from Tbl2 where PID = " & lvw.ListItems(I)
            DB.Execute StrSql
    StrSql = "delete * from Tbl1 where ID = " & lvw.ListItems(I)
            DB.Execute StrSql
       lvw.ListItems.Remove (I)
           End If
    
    End If
    Next
    I get the msgbox pops up the same number of checked rows.
    If for example I have 5 records checked on the listview, I get 5 messages asking to confirm the suppression.

  2. #2
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    447

    Re: Need little help to void repeating msgbox

    All I did was re-arrange to put the msgbox prompt outside of the loop, and then the loop only executes if Yes is clicked.

    Code:
    Dim Msg As String
    Msg = MsgBox("Voulez Vous vraiment supprimer ce dossier?", vbQuestion Or vbYesNo)
    
    If Msg = vbYes Then
      For I = lvw.ListItems.Count To 1 Step -1
        If lvw.ListItems.Item(I).Checked = True Then
          StrSql = "delete * from Tbl2 where PID = " & lvw.ListItems(I)
          DB.Execute StrSql
          StrSql = "delete * from Tbl1 where ID = " & lvw.ListItems(I)
          DB.Execute StrSql
          lvw.ListItems.Remove (I)
        End If
      Next
    End If

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    612

    Re: [RESOLVED] Need little help to void repeating msgbox

    It worked
    thank you a lot

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width