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:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Dim Response As Integer Set rs = New ADODB.Recordset Set cat = New ADOX.Catalog Dim cmd As ADODB.Command If GetAsyncKeyState(vbKeyDelete) Then If Not lvwGroups.SelectedItem Is Nothing Then For Each tbl In cat.Tables If lvwGroups.SelectedItem = tbl.Name Then Response = MsgBox("Are you sure you want to delete this group?", vbQuestion, "Confirm operation") If Response = vbYes Then cat.Tables.Delete tbl Else Exit Sub End If End If Next ElseIf lvwVolumes.SelectedItem <> "" Then For i = 1 To lvwVolumes.ListItems.Count If lvwVolumes.ListItems(i).Selected = True Then rs.Open "SELECT * FROM " & lvwVolumes.ListItems(i), dtaVolumes.ConnectionString, adOpenKeyset, adLockOptimistic Response = MsgBox("Are you sure you want to delete this volume?", vbQuestion + vbYesNo, "Confirm operation") If Response = vbYes Then If Not rs.BOF Then rs.MoveFirst Do Until rs.EOF If lvwVolumes.SelectedItem = rs.Fields(0).Value Then rs.Delete adAffectCurrent rs.Update rs.MoveNext Else rs.MoveNext End If Loop lvwVolumes.ListItems.Remove lvwVolumes.SelectedItem.Index Else Do Until rs.EOF If lvwVolumes.SelectedItem = rs.Fields(0).Value Then rs.Delete adAffectCurrent rs.Update rs.MoveNext Else rs.MoveNext End If Loop lvwVolumes.ListItems.Remove lvwVolumes.SelectedItem.Index End If End If End If Set rs = Nothing Next i End If End If End Sub




Reply With Quote