|
-
Aug 16th, 2000, 07:48 AM
#1
Thread Starter
Hyperactive Member
Hello again, I thought I'd strike again while the iron is hot!!
Ok, I have 2 events (addfaultcause and deletefaultcause) - on_click
I want to be able to multiselect the items in my listbox (lstfaultcause) and be able to delete the items from both the list box and my SQL table. At present I can delete only one selection at a time, but I'd like to be able to select multiple entries and delete them all at once.
Can someone help? I need to be able to keep the index (shown in code below). I'm using RDO to connect
---Code Begins---
Code:
Private sub addfaultcause_click()
Dim infault As String
infault = InputBox("Please enter the Fault Cause? ", "Enter Fault Cause", "")
If infault = "" Then Exit Sub
ans = MsgBox("Are you Sure? ", vbQuestion + vbYesNo, "Question")
If ans = 6 Then
cnCon.Connect = "uid=sa;pwd=;server=" & txtsvr & ";driver={SQL Server};database=" & txtdb & ";"
cnCon.CursorDriver = rdUseOdbc
cnCon.EstablishConnection 'rdDriverNoPrompt
cnCon.AddCause infault
cnCon.Close
lstfaultcause.AddItem (infault)
End Sub
Private Sub deletefaultcause_click()
Dim DelSet As rdoResultset
cnCon.Connect = "uid=sa;pwd=;server=" & txtsvr & ";driver={SQL Server};database=" & txtdb & ";"
cnCon.CursorDriver = rdUseOdbc
cnCon.EstablishConnection 'rdDriverNoPrompt
cnCon.DelCause lstfaultcause.ItemData(lstfaultcause.ListIndex) 'Delcause is SQL-Defined code
Set DelSet = cnCon.LastQueryResults
lstfaultcause.RemoveItem (lstfaultcause.ListIndex)
cnCon.Close
end sub
I guess that I'd have to change the deletefaultcause_click event with need code to allow Multiselect in the list box.
Thanks
Craig.
-
Aug 17th, 2000, 07:54 AM
#2
Fanatic Member
I have never used rdo and ODBC but maybe this will help. Have you tried traversing through the items in the list and if selected remove the item in the list and the subsequent record from the database.
The following code will remove the highlighted rows from the listbox, it works from the last to the first this is because I use the listCount property.
Code:
Dim intLoop As Integer
For intLoop = List1.ListCount - 1 To 0 Step -1
If List1.Selected(intLoop) Then
List1.RemoveItem (intLoop)
'place the relevant record delete code here also
End If
Next
-
Aug 17th, 2000, 09:21 AM
#3
Thread Starter
Hyperactive Member
Thanks... That did the trick! I was nearly there with the code, as I tried something similar but never used the correct syntax.
I'm a very new VB programmer as you can see...
Thanks again,
These forums are great!
Craig.
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
|