Delete records from a table using controls on a subform (1 Viewer)

brainox

Registered User.
Local time
Today, 08:40
Joined
May 22, 2013
Messages
24
I have a sub form that allows users to add staff to a project team, once added it populates a table which updates the subform showing the selected employee. I am trying to enable a delete function that allows users to remove an employee from the project team in the subform showing selected staff. Here is the code I have so far, but it doesn't work;
Code:
Private Sub Command4_Click()
Dim dbs As Database
Dim rs As Recordset
Dim sqlstr As String
Set dbs = CurrentDb
sqlstr = "DELETE tbl_CapexStaff.* FROM tbl_CapexStaff WHERE CAP_ID = Forms!frm_Switchboard.CAP_Live"
dbs.Execute (sqlstr)
End Sub
Any ideas
Cheers
 

pr2-eugin

Super Moderator
Local time
Today, 08:40
Joined
Nov 30, 2011
Messages
8,494
Try,
Code:
sqlstr = "DELETE tbl_CapexStaff.* FROM tbl_CapexStaff WHERE CAP_ID = " & Forms!frm_Switchboard.CAP_Live
 

missinglinq

AWF VIP
Local time
Today, 03:40
Joined
Jun 20, 2003
Messages
6,420
Why not simply

Code:
DoCmd.RunCommand acCmdSelectRecord      
DoCmd.RunCommand acCmdDeleteRecord
or, if you will sometimes start to enter a new record, then change your mind and want to 'delete' that incomplete record

Code:
If Me.NewRecord = False Then
    DoCmd.RunCommand acCmdSelectRecord      
    DoCmd.RunCommand acCmdDeleteRecord
 Else
   If Me.Dirty = True Then Me.Undo
End If
Linq ;0)>
 

brainox

Registered User.
Local time
Today, 08:40
Joined
May 22, 2013
Messages
24
Why not simply

Code:
DoCmd.RunCommand acCmdSelectRecord
Code:
[B]DoCmd.RunCommand acCmdDeleteRecord[/B]
or, if you will sometimes start to enter a new record, then change your mind and want to 'delete' that incomplete record

Code:
If Me.NewRecord = False Then
Code:
[B]   DoCmd.RunCommand acCmdSelectRecord      [/B]
[B]   DoCmd.RunCommand acCmdDeleteRecord[/B]
[B]Else[/B]
[B]  If Me.Dirty = True Then Me.Undo[/B]
[B]End If[/B]
Linq ;0)>

This worked great
Thanks a lot
 

Users who are viewing this thread

Top Bottom