Results 1 to 4 of 4

Thread: Why isn't this working? [SOLVED]

  1. #1

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

    Why isn't this working? [SOLVED]

    For some reason, when it encounters GetAsyncKeyState, it skips all the way to the end of the sub. I am hitting the Delete key, and the KeyPreview property on the form is set to True.

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     Dim Response As Integer
    3.     Set rs = New ADODB.Recordset
    4.     Set cat = New ADOX.Catalog
    5.     Dim cmd As ADODB.Command
    6.     If GetAsyncKeyState(vbKeyDelete) Then
    7.         If Not lvwGroups.SelectedItem Is Nothing Then
    8.             For Each tbl In cat.Tables
    9.                 If lvwGroups.SelectedItem = tbl.Name Then
    10.                     Response = MsgBox("Are you sure you want to delete this group?", vbQuestion, "Confirm operation")
    11.                     If Response = vbYes Then
    12.                         cat.Tables.Delete tbl
    13.                     Else
    14.                         Exit Sub
    15.                     End If
    16.                 End If
    17.             Next
    18.         ElseIf lvwVolumes.SelectedItem <> "" Then
    19.             For i = 1 To lvwVolumes.ListItems.Count
    20.                 If lvwVolumes.ListItems(i).Selected = True Then
    21.                     rs.Open "SELECT * FROM " & lvwVolumes.ListItems(i), dtaVolumes.ConnectionString, adOpenKeyset, adLockOptimistic
    22.                     Response = MsgBox("Are you sure you want to delete this volume?", vbQuestion + vbYesNo, "Confirm operation")
    23.                     If Response = vbYes Then
    24.                         If Not rs.BOF Then
    25.                             rs.MoveFirst
    26.                             Do Until rs.EOF
    27.                                 If lvwVolumes.SelectedItem = rs.Fields(0).Value Then
    28.                                     rs.Delete adAffectCurrent
    29.                                     rs.Update
    30.                                     rs.MoveNext
    31.                                 Else
    32.                                     rs.MoveNext
    33.                                 End If
    34.                             Loop
    35.                             lvwVolumes.ListItems.Remove lvwVolumes.SelectedItem.Index
    36.                         Else
    37.                             Do Until rs.EOF
    38.                                 If lvwVolumes.SelectedItem = rs.Fields(0).Value Then
    39.                                     rs.Delete adAffectCurrent
    40.                                     rs.Update
    41.                                     rs.MoveNext
    42.                                 Else
    43.                                     rs.MoveNext
    44.                                 End If
    45.                             Loop
    46.                             lvwVolumes.ListItems.Remove lvwVolumes.SelectedItem.Index
    47.                         End If
    48.                     End If
    49.                 End If
    50.                 Set rs = Nothing
    51.             Next i
    52.         End If
    53.     End If
    54. End Sub
    Last edited by hothead; May 15th, 2004 at 01:17 PM.

  2. #2

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Ok, I edited this code rather heavily, and part of it has been fixed. However, another problem remains. It does the same thing with this code:


    VB Code:
    1. ElseIf GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyD) Then
    2.         Response = MsgBox("Are you sure you want to delete this group and all volumes in it?", vbQuestion + vbYesNo, "Confirm operation")
    3.         If Response = vbYes Then
    4.             For Each tbl In cat.Tables
    5.                 If tbl.Name = lvwGroups.SelectedItem Then
    6.                     cat.Tables.Delete tbl
    7.                     lvwGroups.ListItems.Remove lvwGroups.SelectedItem.Index
    8.                 End If
    9.             Next
    10.         End If
    11.     End If

    This time, the If statement works, and the message box is displayed. However, the problem occurs after I click Yes. Nothing happens. The code seems to skip it altogether (I ran through it with F8)

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Have you stepped through to see what the value of "Response" is, after you click the "Yes" button?
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I got it. The catalog was not opening a connection to the database.
    Last edited by hothead; May 15th, 2004 at 01:17 PM.

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