Deleting Records in a subform after change in field on main form.

B

Bretona10

Hi everyone, I have a data entry form [RMA Entry Form]with one subform
[RMADetail Form]. There is a field on the mainform [combo32] that when its
value changes I want to delete any existing records in the subfor.

Thanks in advance
Bret
 
B

banem2

Hi everyone, I have a data entry form [RMA Entry Form]with one subform
[RMADetail Form]. There is a field on the mainform [combo32] that when its
value changes I want to delete any existing records in the subfor.

Thanks in advance
Bret

To delete all records in subform, use AfterUpdate event of combo32.
This will delete "any existing records" (you didn't mention is the
subform is linked with main form and you want to delete only the
records you see):

Sub combo32_AfterUpdate()
On Error GoTo ErrHandler
Dim strSQL As String
strSQL = "DELETE * FROM RMADetail"
CurrentDb.Execute strSQL, dbFailOnError
[RMADetail Form].Requery
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub

Regards,
Branislav Mihaljev
Microsoft Access MVP
 
B

Bretona10

Hi everyone, I have a data entry form [RMA Entry Form]with one subform
[RMADetail Form]. There is a field on the mainform [combo32] that when its
value changes I want to delete any existing records in the subfor.

Thanks in advance
Bret

To delete all records in subform, use AfterUpdate event of combo32.
This will delete "any existing records" (you didn't mention is the
subform is linked with main form and you want to delete only the
records you see):

Sub combo32_AfterUpdate()
On Error GoTo ErrHandler
Dim strSQL As String
strSQL = "DELETE * FROM RMADetail"
CurrentDb.Execute strSQL, dbFailOnError
[RMADetail Form].Requery
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub

Regards,
Branislav Mihaljev
Microsoft Access MVP
Yes it is linked and I only want to delete the visible records.
My form is Data Entry Mode with no record movement keys visible.

Thanks
 
B

banem2

Hi everyone, I have a data entry form [RMA Entry Form]with one subform
[RMADetail Form]. There is a field on the mainform [combo32] that when its
value changes I want to delete any existing records in the subfor.
Thanks in advance
Bret
To delete all records in subform, use AfterUpdate event of combo32.
This will delete "any existing records" (you didn't mention is the
subform is linked with main form and you want to delete only the
records you see):
Sub combo32_AfterUpdate()
On Error GoTo ErrHandler
Dim strSQL As String
strSQL = "DELETE * FROM RMADetail"
CurrentDb.Execute strSQL, dbFailOnError
[RMADetail Form].Requery
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
Regards,
Branislav Mihaljev
Microsoft Access MVP

Yes it is linked and I only want to delete the visible records.
My form is Data Entry Mode with no record movement keys visible.

Thanks

In this case you will need to change this line

strSQL = "DELETE * FROM RMADetail"

to

strSQL = "DELETE * FROM RMADetail " & _
"WHERE IDField = " & Me.IDField

(change "IDField" to your ID field name).

Regards,
Branislav Mihaljev
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top