|
-
May 15th, 2004, 07:03 AM
#1
Thread Starter
Fanatic Member
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:
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
Last edited by hothead; May 15th, 2004 at 01:17 PM.
-
May 15th, 2004, 12:13 PM
#2
Thread Starter
Fanatic Member
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:
ElseIf GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyD) Then
Response = MsgBox("Are you sure you want to delete this group and all volumes in it?", vbQuestion + vbYesNo, "Confirm operation")
If Response = vbYes Then
For Each tbl In cat.Tables
If tbl.Name = lvwGroups.SelectedItem Then
cat.Tables.Delete tbl
lvwGroups.ListItems.Remove lvwGroups.SelectedItem.Index
End If
Next
End If
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)
-
May 15th, 2004, 12:34 PM
#3
Frenzied Member
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
-
May 15th, 2004, 01:06 PM
#4
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|