Nihilist
01-08-2001, 01:54 AM
I'm having a problem with my project. I'm using a SSTab, 3 tabs all in all, and each tab has an ADO Datagrid, all using one single database. The problem now is, while viewing the record, there are 3 functions; add, edit and delete. The add function works, the other 2 are the problems. Instead of normally highlighting a record and pressing the"Delete" key, I want the user to highlight it and press a "Delete" command button. Makai already helped me with this one, but the problem now is..it deletes the LAST record, and not the one highlighted. Also, editing is not possible until the user clicks on an "Edit" command button, making the datagrid editable, then if a user presses the "Enter" key, changes will be saved, and if the user presses the "Esc" key, nothing is done. I have included an image of a tab with these features..solutions or alternatives will be greatly appreciated. Thank you!
Heico
01-08-2001, 09:02 AM
You didn't give much information, but I presume you use the ADODC control to fill the grid. In that case this might help. If not, then mail how you access the table and I'll see what I can do. (next time add the code so people can see where the problem might be)
To delete the right record add this code to the delete button :
dbTest.Recordset.Delete adAffectCurrent
Where dbTest should be replaced with the name of your ADODC control.
Editing is a little more complicated, and I'm still not sure if this is the best way, but it'll work. When the user presses the edit-button, editing is enabled, so allowupdate is set to true(right?) the user edits the field and then presses return. So and add this code :
If KeyAscii = vbKeyReturn Then
cmdEdit.SetFocus
dgTest.AllowUpdate = False
End If
(dgTest is the datagrid control). When the user presses the return key the focus shifts to another control (in this case cmdEdit but that doesn't matter) thereby forcing the update to the database. After that allowupdate is set to false, so the user can't edit in the grid anymore.
Same with the escape-key, just put the following code in the keydown event :
If KeyCode = vbKeyEscape Then
dgTest.AllowUpdate = False
End If
Because you don't want an update don't shift the focus.
Its a long story, but I hope it helps. If not mail me, good luck with it,
Heico
Nihilist
01-11-2001, 08:06 PM
This is the coding provided by makai (Thanks for the help! Much appreciated!)
I've tried these out, only the editing isn't working. The deleting works though..I'll appreciate any other help. Thanks!
Private Sub DBGrid1_AfterColEdit(ByVal ColIndex As Integer)
MsgBox "Edited"
End Sub
assuming your ADO recordset is defined as rs
Private Sub Command1_Click()
rs.Delete
MsgBox "Deleted"
End Sub