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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting records from database

Status
Not open for further replies.

chris921

Technical User
Mar 9, 2004
82
GB
Is there an easy way to delete records from a database?

Many thanks,

*Frustrated* Chris
 
Records are in "Tables" ... not "Databases"
Code:
Delete * From myTable
will delete all records from the table "myTable
 
I know the sql, but its getting the VB to allow me to use it!!

Example bit of code (doesnt delete anything, it runs and doesnt crash the program though)

Code:
            mySQL = "Delete * from C where CID =" & cmatt
            AccessData.AccessDatabase.Execute mySQL

that should be deleting the record? but it wont?
 
And what sort of objects are
[blue]AccessData[/blue] and
[blue]AccessDatabase[/blue]?

 
Try

mySQL = "Delete from C where CID =" & cmatt
AccessData.AccessDatabase.Execute mySQL

Swi
 
Also, what data type is CID? If it is text surround it in apostrophes.

"Delete from C where CID ='" & cmatt & "'"


Swi
 
Really the asterisk should not matter in the SQL statement but it is not necessary.

Swi
 
Code:
Try

mySQL = "Delete from C where CID =" & cmatt
            AccessData.AccessDatabase.Execute mySQL 
Swi

Tried that - no difference.

cmatt is an integer read in from a form, CID is the unique integer id's held in the table.
 
Do you have records matching this condition in your table?
If you fire select with above condition, do you get any count?
Insert one statement after your delete query to find out records affected by the delete operation.

Sharing the best from my side...

--Prashant--
 
Don't know whether it makes much difference but i found that my Delete Statements only work when read from a variable and with a Space after the equals sign.

Code:
Dim sSQL As String

sSQL = "DELETE * FROM C WHERE CID = " & cmatt

AccessData.AccessDatabase.Execute sSQL

Also, you may want to look at your coding of the Connection Execute Statement. What did you declare as your Connection Variable?
Normally, the connection variable will be enough to issue the Execute statement???

Code:
AccessData.Execute sSQL

Assuming, of course, that AccessData is your Connection Variable...

HTH

Jag14

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top