?
Solved

Deleting records based on data matches in two different tables

Posted on 2014-11-11
2
Medium Priority
?
128 Views
Last Modified: 2014-11-12
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!
0
Comment
Question by:Megin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 40436599
You need to modify your query a bit:
strsql = "Delete Act_SubTO_Date.* from Act_SubTO_Date INNER JOIN [Activities] ON Act_SubTO_Date.ActID =  [Activities].ActID " &_
" where Act_SubTO_Date[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]

Open in new window

Basically, you need to join the tables first, and then delete. Also, Date literals need to be enclosed in ##
0
 

Author Closing Comment

by:Megin
ID: 40437967
It works!

Thank you!!!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question