Form vs Subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can't seem to delete my most recent record. I have a form ("Direct_frm")
that works great by itself. When I hit the cancel button ("Cancel3") the code
will find the ID and delete it from my table ("Sales_tbl") and close the form
("Sales_frm"). However, when I put it in the form ("Sales_frm") as a subform
the code doesn't seem to work. The record doesn't delete and the form doesn't
close. It might have to do with the refresh???
Any help is appreciated:

Private Sub Cancel3_Click()

On Error GoTo Err_Cancel3

Me.Refresh
CurrentDb.Execute "DELETE * FROM [Sales_tbl] Where [ID] =" &
[Forms]![Direct_frm]![ID]
DoCmd.Close acForm, "Sales_frm", acSaveYes

Err_Cancel3:

If Err.Number = 3075 Then
DoCmd.Close acForm, "Sales_frm", acSaveYes
Else
End If

End Sub
 
JJ said:
I can't seem to delete my most recent record. I have a form
("Direct_frm") that works great by itself. When I hit the cancel
button ("Cancel3") the code will find the ID and delete it from my
table ("Sales_tbl") and close the form ("Sales_frm"). However, when I
put it in the form ("Sales_frm") as a subform the code doesn't seem
to work. The record doesn't delete and the form doesn't close. It
might have to do with the refresh???
Any help is appreciated:

Private Sub Cancel3_Click()

On Error GoTo Err_Cancel3

Me.Refresh
CurrentDb.Execute "DELETE * FROM [Sales_tbl] Where [ID] =" &
[Forms]![Direct_frm]![ID]
DoCmd.Close acForm, "Sales_frm", acSaveYes

Err_Cancel3:

If Err.Number = 3075 Then
DoCmd.Close acForm, "Sales_frm", acSaveYes
Else
End If

End Sub

A subform is not technically "open" and is not included in the Forms collection.
You have to reference it via the subform control in the parent form.

Forms!Sales_frm!SubformControlName.Form![ID]

Note that the subform control's name is what you use above which might not be
the same as the name of your form displayed inside it.
 
....still doesn't seem to be working. the subform is labeled "Child144". So, I
changed the code to as follows:

Private Sub Cancel3_Click()

On Error GoTo Err_Cancel3

Me.Refresh
CurrentDb.Execute "DELETE * FROM [Sales_tbl] Where [ID] =" &
[Forms]![Sales_frm]![Child114.FORM]![ID]
DoCmd.Close acForm, "Sales_frm", acSaveYes

Err_Cancel3:

If Err.Number = 3075 Then
DoCmd.Close acForm, "Sales_frm", acSaveYes
Else
End If

End Sub



Rick Brandt said:
JJ said:
I can't seem to delete my most recent record. I have a form
("Direct_frm") that works great by itself. When I hit the cancel
button ("Cancel3") the code will find the ID and delete it from my
table ("Sales_tbl") and close the form ("Sales_frm"). However, when I
put it in the form ("Sales_frm") as a subform the code doesn't seem
to work. The record doesn't delete and the form doesn't close. It
might have to do with the refresh???
Any help is appreciated:

Private Sub Cancel3_Click()

On Error GoTo Err_Cancel3

Me.Refresh
CurrentDb.Execute "DELETE * FROM [Sales_tbl] Where [ID] =" &
[Forms]![Direct_frm]![ID]
DoCmd.Close acForm, "Sales_frm", acSaveYes

Err_Cancel3:

If Err.Number = 3075 Then
DoCmd.Close acForm, "Sales_frm", acSaveYes
Else
End If

End Sub

A subform is not technically "open" and is not included in the Forms collection.
You have to reference it via the subform control in the parent form.

Forms!Sales_frm!SubformControlName.Form![ID]

Note that the subform control's name is what you use above which might not be
the same as the name of your form displayed inside it.
 
Got it! Thanks!

JJ said:
...still doesn't seem to be working. the subform is labeled "Child144". So, I
changed the code to as follows:

Private Sub Cancel3_Click()

On Error GoTo Err_Cancel3

Me.Refresh
CurrentDb.Execute "DELETE * FROM [Sales_tbl] Where [ID] =" &
[Forms]![Sales_frm]![Child114.FORM]![ID]
DoCmd.Close acForm, "Sales_frm", acSaveYes

Err_Cancel3:

If Err.Number = 3075 Then
DoCmd.Close acForm, "Sales_frm", acSaveYes
Else
End If

End Sub



Rick Brandt said:
JJ said:
I can't seem to delete my most recent record. I have a form
("Direct_frm") that works great by itself. When I hit the cancel
button ("Cancel3") the code will find the ID and delete it from my
table ("Sales_tbl") and close the form ("Sales_frm"). However, when I
put it in the form ("Sales_frm") as a subform the code doesn't seem
to work. The record doesn't delete and the form doesn't close. It
might have to do with the refresh???
Any help is appreciated:

Private Sub Cancel3_Click()

On Error GoTo Err_Cancel3

Me.Refresh
CurrentDb.Execute "DELETE * FROM [Sales_tbl] Where [ID] =" &
[Forms]![Direct_frm]![ID]
DoCmd.Close acForm, "Sales_frm", acSaveYes

Err_Cancel3:

If Err.Number = 3075 Then
DoCmd.Close acForm, "Sales_frm", acSaveYes
Else
End If

End Sub

A subform is not technically "open" and is not included in the Forms collection.
You have to reference it via the subform control in the parent form.

Forms!Sales_frm!SubformControlName.Form![ID]

Note that the subform control's name is what you use above which might not be
the same as the name of your form displayed inside it.
 

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

Back
Top