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!

Deleting Records 1

Status
Not open for further replies.

WarrenB

Programmer
Feb 7, 2001
38
GB
Is it possible to delete records via a macro or via vba coding? If so how is this achieved?

Thanks =================
Warren Brown
wazzer@btinternet.com
=================
 
you can use an SQL statement via VBA. Assign a string variable the SQL statement and then use the command:

DoCmd.RunSQL (SQLstring)

hope this helps
wah
 
My experience of Access is very limited, can you be more specific please?

Thanks =================
Warren Brown
wazzer@btinternet.com
=================
 
Here is an example of a simple one i have used. If you have any questions about any part of the code let me know. Access help file will help shed some light on a few things.


the '+ _ ' in the SQL part allows you to continue the code onto the next line. Helps make things look a little neeter in VBA.

bol
wah



Dim strSQL As String ' Holds SQL statement

If (MsgBox("You can not undo this action. Press OK to proceed with the deletion.", vbOKCancel, "Delete Employee")) = 1 Then 'Confirms deletion

strSQL = "" + _
"DELETE * " + _
"FROM tblEmployeeDetails " + _
"WHERE ([tblEmployeeDetails].[EmpID] = [Forms]![Main]![MainSubForm].[Form]!EmpID)"

DoCmd.SetWarnings (False) 'Turns the pesky warnings off
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True) 'Turns the pesky warnings on
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top