Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete record in table from a Recordset

Status
Not open for further replies.

imendi

Programmer
Oct 14, 2002
33
ES
Hello,

I have the following code behind a delete button in a Form:

MySQL = "select * from Mytable where (MyTable.Cod = " & Me!txtCod & ")"
Set Myrs = MyDB.OpenRecordset(MySQL , DB_OPEN_DYNASET)
If Myrs.recordcount > 0 Then
Myrs.Delete
MsgBox "Register deleted successfully"
End If

My problem is that is does show the msgbox, but it does not delete the row in the table MyTable.

Many thanks,

im
 
You could use...

MySQL = "DELETE * FROM Mytable where (MyTable.Cod = " & Me!txtCod & ")"

MyDB.Execute (MySQL)
There are two ways to write error-free programs; only the third one works.
 
Well, it is something funny, because I tried your code and it does work either.
As like with my code, it doesn´t give any error message, but it does not delete the row either !

strange...

I keep finding out the reasons.

Regards and thanks for your reply.

im
 
What is the data type of MyTable.Cod

There are two ways to write error-free programs; only the third one works.
 
Solved !

For some reason it did not want to allow me to delete a record while the form was open.

Thanks for you interest, GHolden.

imendi

 
Have you tried stepping through the code to check the value
Me!txtCod when it's passed
There are two ways to write error-free programs; only the third one works.
 
Well done !!

There are two ways to write error-free programs; only the third one works.
 
Just for the records, I think everything come from the point that in the real situation there is a form with a subform on it. I tried to delete a record of the main form in table1 but there is still a relationship of that record in table2, which is shown in the subform.

By closing the form BEFORE you run the code you provided me with, it works.
If you close the form after the code you provided, it will not work as I supposse Access (Access 2.0 to be precise) keeps the record as long as there is a relationship opened, and will not delete it when you close it.

Rgds,

im
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top