473,699 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ 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(Payme nt_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.Execu te strSQL

strSQL = "DELETE FROM Payment_Detail_ Table where Payment_id= " & Payment_id &
";"
CurrentDb.Execu te strSQL
Else
Remarks.SetFocu s
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.Exec ute 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 3310
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(Payme nt_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.Execu te strSQL

strSQL = "DELETE FROM Payment_Detail_ Table where Payment_id= " & Payment_id &
";"
CurrentDb.Execu te strSQL
Else
Remarks.SetFocu s
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.Exec ute 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 "Relationsh ips" 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
11185
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 subform in the Main form. I'd like to double click on the selected file in the listbox and load that record into the the Subform, easy
1
3728
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 accesses the record corresponding to the row clicked. To get this row, I tried using Me.Parent.Bookmark. Unfortunately, this gets the "Current Record" which is set via the navigation
3
7820
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 acCmdDelete Record? Thanks! Maria
1
4436
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 created a MainTable (and related form), which has an associated SubForm (popup) along with its underlying, separate Table. The tables' relationship is one to many respectively. The primary key
1
3140
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 called Client Contacts. I want to print the current record using the ID field in the Client Contacts subform in a report. I want to print to a report called MAIN CLIENT INFO using the current record in the subform.
12
12938
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 we prevent this from happening? Thanks. ming
5
6988
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 to complain about nulls and then about 'can't repeat an index'. To solve this I wrote code on the main form's subform enter event (I'm surprised I found it. I must have spent an hour trying to program the enter and exit events from the subform...
8
18221
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 orientated form. Both forms contain records of 'shifts' I want to be able to select a record (a shift) in the subform, and be able to set the parent form's current record to that record, through the identifying primary key that a shift record has...
5
1634
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 is, when I enter ID the related information is displayed in the subform but when I close the subform, in the main form the record displayed is the very first record of the table, not the current record. What I want is when I close the subform it...
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3053
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 we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.