Form/subform button

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

Guest

I have a button on a form, which I want to make visible only when the subform
"disappears" if a user deletes all linking records in the subform. (The
record source of the subform is a table in a many-to-one relationship with
the source table of the form..)

Is there a somewhat simple way to do this? Thanks!
Terri
 
Terri,

First, you may want to create a public sub on your form, similar to the
following:

Public Sub MakeSubButtonVisible()
Me!MyButton.Visible = Me!MySubFormControName.Form.RecordsetClone.EOF
End If

Then make sure you call it from your form's Current event.
And on your subform's AfterDelConfirm event you can place a call to that
parents function:

Me.Parent.MakeSubButtonVisible

HTH
 
I tried this, but am getting an error when I open the form and it tries to
run the function: "Run-time error 2455 - You entered an expression that has
an invalid reference to the property Form/Report."

Just to clarify - the button is on the form, not the subform. This is how I
created the function:

Public Sub MakeSubButtonVisible()
Me!cmdCoverPage.Visible = Me!frmWaveCorderInfoSub.Form.RecordsetClone.EOF
End Sub

Thanks - Terri
 
Terri,

Make sure that you have used subform CONTROL's name not SUBFORM's name in
your expression.

HTH
 
Yes, I definitely checked for that. I did a search on this error and also
made sure I had the proper library references (I do).

The error happens when I am trying to open the form to enter new records for
the first time in the subform. Once I've entered records, there is no error
when I open the form, or delete records in the subform.

Also, when I delete the last subform record, the button does not become
visible on the form.
 
First off, Sergey, thank for you helping me with this! I'm working with the
code you gave me and almost have it working..

I moved the public sub from the form to the subform, with the following code:
Forms!MyMainForm.cmdCoverPage.Visible = Me.RecordsetClone.EOF

Then, I call the sub from the subform's AfterDelConfirm event. It does work
(i.e. the button cmdCoverPage becomes visible) if I just have one subform
record and delete it. However, if I have more than one subform record and
delete them all in one sitting, the button does not become visible. It DOES
work if I delete one record, go out of the form, go back in, delete, etc.,
until the records are all gone. But somehow the EOF does not seem to be
happening when all records are deleted, when there was more than one record -
?

Thanks again! Terri
 
Back
Top