Avatar of SteveL13
SteveL13Flag for United States of America

asked on 

SQL delete code

What would the VBA code be to delete a specific record from a table?

Something like:

Delete * from tblName where Client= me.txtclientID

??
Microsoft AccessVBA

Avatar of undefined
Last Comment
Ryan Chong
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

you need to use ADO object library, apparently an ADODB.Connection object, and then use it to connect to your database with a valid connection string, and then using this object's Execute method to execute the Delete SQL statement you wish to be executed.
Avatar of SteveL13
SteveL13
Flag of United States of America image

ASKER

Sorry.  Not following.  Do not know how to write the code.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of SteveL13
SteveL13
Flag of United States of America image

ASKER

Here is my query designer SQL:

DELETE tblClient.*, tblClient.ClientID
FROM tblClient
WHERE (((tblClient.ClientID)=[Forms]![frmClients]![txtClientID]));

How do I convert that to VBA code?
Avatar of SteveL13
SteveL13
Flag of United States of America image

ASKER

Rey,

Thank you.  You posted the solution just as I was posting my last reply.

It is number and your solution worked perfectly.  I wish there was a guide somewhere to assist in writing simple SQL code like this.
Avatar of PatHartman
PatHartman
Flag of United States of America image

@Ryan,
The default library for Access is DAO not ADO.  DAO is optimized for working with Jet/ACE so there is no reason to use ADO.  As for other RDBMS', I haven't seen any analysis comparing DAO and ADO using the ACE library so I can't say which is better.  All the analysis that I find is for Jet and Jet has been gone since 2007.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>>The default library for Access is DAO not ADO
Ok, not aware this was in Access TA.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo