How to Delete Subform Record? (1 Viewer)

adeem

New member
Local time
Today, 07:38
Joined
Dec 15, 2012
Messages
5
How to Delete current record in a subform using a command button? When i try to delete any record its only delete from main form ,its record does not delete from linked form.

Please Help me out to resolve this issue.

Thanks
Adeem
 

JHB

Have been here a while
Local time
Today, 16:38
Joined
Jun 17, 2012
Messages
7,732
[FONT=&quot]Try look at the [/FONT][FONT=&quot]referential integrity [/FONT][FONT=&quot]between the tables..[/FONT]
 

adeem

New member
Local time
Today, 07:38
Joined
Dec 15, 2012
Messages
5
Thanks for your reply! i am a new comer in access i don't know much about it , i have Google out that mostly peoples suggested blow coding .

Dim strSQL As String

strSQL = "DELETE * FROM table WHERE PK = " & Me.controlname & ";"
CurrentDB.Execute strSQL
Me.subformname.Form.Requery

But i am confused:confused: to understand it ,i am also going to attach an image of my form and tables detail if you can help me out accordingly or suggest me a better way to resolve this issue.

Thanks
Adeem
 

Attachments

  • sample.png
    sample.png
    11.4 KB · Views: 189

JHB

Have been here a while
Local time
Today, 16:38
Joined
Jun 17, 2012
Messages
7,732
Try Google for "relation+ms-access", it will give you some idea how your tables should be linked together.
 

rodmc

Registered User.
Local time
Today, 14:38
Joined
Apr 15, 2010
Messages
514
Like JHB says, you need to understand the relations between your tables and be 110% sure you want to delete that record before doing it.
I delete very few records from any of my access databases.
If you are determined to delete a record from the subform you need to bring up the relationships window, identify the link between your form and subform and look for it in the relationships window, when you have done this, click on the link and select the appropriate check box, ie cascade deleted records.
 

Solo712

Registered User.
Local time
Today, 10:38
Joined
Oct 19, 2012
Messages
828
Thanks for your reply! i am a new comer in access i don't know much about it , i have Google out that mostly peoples suggested blow coding .

Dim strSQL As String

strSQL = "DELETE * FROM table WHERE PK = " & Me.controlname & ";"
CurrentDB.Execute strSQL
Me.subformname.Form.Requery

But i am confused:confused: to understand it ,i am also going to attach an image of my form and tables detail if you can help me out accordingly or suggest me a better way to resolve this issue.

Thanks
Adeem

Basically, the SQL command says: "delete everything from table called 'table' if a value of a field called 'PK' equals the control name. "

So, for example, if 'Me.controlname' field is 'Last Name' and holds the name of 'Smith' you would be deleting all the records with the last name 'Smith'. .....just saying, so you are aware. :)

Best,
Jiri
 

adeem

New member
Local time
Today, 07:38
Joined
Dec 15, 2012
Messages
5
Thank you all who help me to resolve this issue............I Google out Relationship and my problem has been solved.:)

Thanks
Adeem
 

Users who are viewing this thread

Top Bottom