473,467 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Deletion of Current Record in Main Form & Subform

41 New Member
Hi,

I have one Form in which i have one subform also which links together by one common_id(Payment_id). When i display record, I need to delete Current record in both form & Table. I used the following code to delete.
---
Dim response
Dim strsql As String

response = MsgBox("Are you sure to Delete?", vbYesNo, "Payment Alteratiion")

If response = vbYes Then
strSQL = "DELETE FROM Payment_Table where Payment_id = " & Payment_id & ";"
CurrentDb.Execute strSQL

strSQL = "DELETE FROM Payment_Detail_Table where Payment_id= " & Payment_id &
";"
CurrentDb.Execute strSQL
Else
Remarks.SetFocus
End If

-----
Its deleting in the main Form data. But, not deleting
in subform data. As well as, it shows the below error which stand 2nd Sql Stmnt of "CurrentDb.Execute strSQL"
--
Run-time error '3075'
syntax error (missing operator) in query expression 'Payment_id='
----

Payment_id is a Control Name.

Believe its clear

Is there any wrong in the code, please suggest me to
proceed further?

Your suggestion & solution would be appreicated GREATLY.

Thanks in advance.

ngr.
Jun 15 '07 #1
1 3302
FishVal
2,653 Recognized Expert Specialist
Hi,

I have one Form in which i have one subform also which links together by one common_id(Payment_id). When i display record, I need to delete Current record in both form & Table. I used the following code to delete.
---
Dim response
Dim strsql As String

response = MsgBox("Are you sure to Delete?", vbYesNo, "Payment Alteratiion")

If response = vbYes Then
strSQL = "DELETE FROM Payment_Table where Payment_id = " & Payment_id & ";"
CurrentDb.Execute strSQL

strSQL = "DELETE FROM Payment_Detail_Table where Payment_id= " & Payment_id &
";"
CurrentDb.Execute strSQL
Else
Remarks.SetFocus
End If

-----
Its deleting in the main Form data. But, not deleting
in subform data. As well as, it shows the below error which stand 2nd Sql Stmnt of "CurrentDb.Execute strSQL"
--
Run-time error '3075'
syntax error (missing operator) in query expression 'Payment_id='
----

Payment_id is a Control Name.

Believe its clear

Is there any wrong in the code, please suggest me to
proceed further?

Your suggestion & solution would be appreicated GREATLY.

Thanks in advance.

ngr.
You should run SQL commands in reversed order.

By the way, you may use DRI (Declarative referrential integrity) instead.
In "Relationships" pane rightclick corresponding table link, choose Edit relationship, check boxes "Enforce referrential integrity" and "Cascade delete related fields". No coding needed.

Good luck.
Jun 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: ChrisR | last post by:
Hi guys My app is a simple Main form with a few Subforms that are not linked, and a few pop forms. Problem is: I have a pop form with a Listbox with a list of records related to the...
1
by: xmp333 | last post by:
Hi, I have a form that is designed as a data sheet view. Attached to this is a subform with some VB code. When the user clicks on a row, the subform should pop up and run the VB code which...
3
by: Maria | last post by:
Is there another way to delete the current record in a subform from the main form, another subform or a sub-subform other than setting focus on a field in the subform and using run command...
1
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have...
1
by: Randy | last post by:
I have tried the code to attach a button to a form and use the help information on coding, but I can't seem to get it to work. I have a main form called MAIN CLIENT INFO2 There is a subform...
12
by: swingingming | last post by:
Hi, in the NorthWind sample database, when clicking on the next navigation button on the new order record with nothing on the subform (order details), we got an order with nothing ordered. How can...
5
by: christianlott1 | last post by:
I admit my form is pretty complex and may need a total overhaul - I have two subforms synchronized on a form through an unbound text box. When I enter a new record in the second subform it used...
8
by: anansi | last post by:
Hi I have a form called 'shiftviewer' and it contains a subform called 'all shifts for current month subform'. the subform is in datasheet view (access 2007) and the main form is a column...
5
by: 130975 | last post by:
Hi, I am working on a database. I have created a main form and three linked forms. When I enter an ID in the main form all the related information is also displayed on the linked forms. The problem...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.