Link to home
Start Free TrialLog in
Avatar of Megin
Megin

asked on

Deleting records based on data matches in two different tables

I have a subform in a form in Access and I need to delete item from it based on two other pieces of information in the form.

The problem I am running into is that one of these pieces of information is in a secondary table.

This should clear it up further:

Table1: ActID, STOid
Table2 (the one I need to delete from): tableid, ActID, ActDate

The form provides the ActDate and the STOid.

I want to delete based on the ActDate and STOid selected in the form.

This is what I have so far, but I know it isn't correct. I am not sure how to make the connection with table1.

Private Sub btn_DeleteAll_Click()
Dim msgRes As VbMsgBoxResult
Dim strsql As String

msgRes = MsgBox("Are you sure you want to reset your report?", vbOKCancel, "Reset Report")
If msgRes = vbCancel Then
Exit Sub

strsql = "Delete from Act_SubTO_Date where [ActDate] = " & Forms("frm_Act_Enter").[Sub_frm_Act_enter_crntrpt].Form.[ActDate] AND [Activities].[STOid] = " & Forms("frm_Act_Enter").[Sub_frm_Act_enter_crntrpt].Form.[cmbsto]"



End Sub

Open in new window


Thank you, in advance!
ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Megin
Megin

ASKER

It works!

Thank you!!!!!!