PDA

Click to See Complete Forum and Search --> : Deleting records


Dillinger4
Oct 13th, 2000, 09:09 AM
Does anyone know if it is possible to delete records
from a record set opened with an SQL string? If i
run this code it produces a runtime error:
(3027 cannot update database or object is read only)
but if i replace the SQL string with an actual table
name the deletions take place and everything is fine.

Private Sub cmdDelete_Click()
Dim responce As String
Dim strSql As String

Set db = OpenDatabase(KeySetting)
strSQL = strSql = "SELECT [Account Information].*, [Route Details].*, [Ticket Information].* FROM ([Account Information] INNER JOIN [Route Details] ON [Account Information].AccountID = [Route Details].AccountID) INNER JOIN [Ticket Information] ON ([Route Details].AccountID = [Ticket Information].AccountID) AND ([Account Information].AccountID = [Ticket Information].AccountID);"

' keysetting is just a public variable that contains the
' path from the GetSetting function.
Set rs = db.OpenRecordset(strSql)
responce = MsgBox("Are you sure that this record is to be deleted?", vbYesNo + vbQuestion)
If responce = vbYes Then
rs.Delete
End If
rs.Close
End Sub

' I wanted to use cascading updates and deletes to make things easier but then i would have to force refrential integrity, which was causing an error.

Thanks All........

vbuser1976
Oct 13th, 2000, 01:22 PM
Have you tried running the SQL string as a stored procedure instead of letting VB do it?

Dillinger4
Oct 13th, 2000, 01:35 PM
Can you do that? Well i guess ill have to break
out my access book and give it a try.
Thanks Bro....

vbuser1976
Oct 13th, 2000, 02:10 PM
If your have an access db, it might not work. But if you have a SQL db, I know that it will definitely work. If you have the money, you should buy this book(I have it as well):

"Database Access with Visual Basic 6" by Jeffrey P. McManus. ISBN: 0-672-31422-3

It has great examples, code, and talks about Jet databases as well as SQL databases. It costs approximately $40 but I got it for $27.99 at http://www.computerbooksexpress.com

Hope this helps.