Click to See Complete Forum and Search --> : Delete a row from DataGrid


John Reynolds
October 18th, 2001, 08:14 AM
Using a data environment (MS Jet 4.0 DB Provider). Have set up commands for each of the 4 tables (not using SQL statements). In frmMain, have DataGrid control with source of deTransfers & member of Location (1 of the tables = command).

The control includes all rows (fields) of the Location table, as it should. Have written procedures to add, edit, & delete a row. Using code below, when user deletes a row, gets error . . . "Row handle referred to a deleted row or a row marked for deletion." HOWEVER, when I step through (F8), execution does not stop! Works fine. Row gets deleted from record set & DB! When I do not step through & execution halts & I press Debug, execution is on the line following .Delete.

What is going on? Thanks for any suggs.
John



private Sub mnuDeleteLocation_Click()
on error GoTo HandleError
With deTransfers.rsLocation
.Delete 'Delete the current record
.MoveNext 'EXECUTION stops here (after .Delete) when NOT debugging - Move to the following record
If .EOF then 'If last record deleted
.MovePrevious
If .BOF then 'If BOF and EOF true, no records remain
MsgBox "The recordset is empty.", vbInformation, "No records"
End If
else: .MoveFirst
End If
End With

Exit Sub

HandleError:
MsgBox "Unable to carry out requested action.", vbInformation, "Video Bonanza"
on error GoTo 0


End Sub

John G Duffy
October 18th, 2001, 10:03 AM
You are running into asynchronous processing problems. Stepping through at the speed of mouse clicks allows ADO or whatever to complete its work before running into problems.
Try doing a .Refresh or .Requery after the initial deletion

John G

John Reynolds
October 18th, 2001, 11:23 AM
John, thanks for the suggestion. I tried .Requery but still get message. RecordSet has no .Refresh, but I tried .Resync, but still no change.

Sure appreciate any other suggs. from you.
John R.

John Reynolds
October 19th, 2001, 04:27 PM
John, thanks for the suggestion. I think I've tried everything. It seems like this problem would be more known. (?)

Anyway, would sure appreciate it if you have time to look at it one more time. It's the 1st problem I've had you have not solved (little incentive)! Hey, we're talkin' 10 points . . I'd give you a 1000 if I knew how.

Thanks in any event,
John

John G Duffy
October 20th, 2001, 10:30 AM
John,
I went through the Application Wizard and created a program that uses the Biblio.mdb file using ADO code (Jet 4.0) and the delete code it generated is almost identical to yours so I suspect some external environment is killing you.
Where is your DataBAse located (Server/Local) etc.
Try putting in a DOEVENTS in the delete routine to allow other processes to gain control.
Also I suggest you create a new project and use the data Form Wizard using your database and environment to see what kind of code it generates. Although it does not generate perfect code, it does work under optimal conditions

John G

John Reynolds
October 22nd, 2001, 09:54 AM
John, thanks for your suggestion about using the Data Form Wizard. I started from scratch, and the app. will delete without error, using my database! So, I'll just try to find the code differences . . . or just go with theirs.

When using the Data Form Wizard, I noticed that using a Class was an option, instead of direct ADO coding. Seems so neat, using a class. Would you suggest that, or stay with ADO coding on the form itself?

Thanks again,
John

John G Duffy
October 22nd, 2001, 10:19 AM
Go with what works or you understand for the time. Once you get it working then play with class modules. If you never used them before, they can be a little confusing. But once you get the gist of a class module, they are most rewarding and flexible.

John G