Re: AddNew button on the Record selector



Jac Tremblay wrote:

>Hi again, Marsh,
>I found out something interesting. I tried this code from the help file to
>list all open forms and, for each one, all the controls they hold:
>' ***********************************
>Dim frm As Form, ctl As Control
>Dim intNbFrm As Integer
>intNbFrm = Forms.Count
>MsgBox "There is actually " & intNbFrm & " from(s) open."
>' List the Forms collection.
>For Each frm In Forms
> ' Print the name of the form.
> Debug.Print "Form name: "; frm.Name
> ' List the Controls collection for each form.
> For Each ctl In frm.Controls
> ' Print the name of each control.
> Debug.Print "Control name >>> "; ctl.Name
> Next ctl
>Next frm
>' ***********************************
>That code shows that there is only one form open and that the subform it
>holds is considered to be a control. That is why I cannot access it as a from.
>What can I do now with that control? Can I still go to it's last record or
>use methods or properties that apply to forms?


You're losing me here. Are you saying that you have to run
a special procedure for a new record on the main form and
another procedure for a new record on the subform? Since
this is a fairly unusual thing to do. I am having trouble
figuring out why and what this is all about.

As far as adressing the subform. As you have seen, a
subform is not in the list of forms that are open in the
Access window. A form object that is displayed in a subform
control is associated with the subform control. From code
in the main form's module, you can address the subform
object's properties through the subform control:
Me.subformcontrol.Form.propertyname

You would get to the subform's last record using the same
kind of reference along with the same logic you used on the
main form:
With Me.subformcontrol.Form.RecordsetClone
If .RecordCount > 0 Then
.MoveLast
Me.subformcontrol.Form.Bookmark = .Bookmark
End If
End With

The subform's Current event is specified in the form used in
the subform control's SourceObject property. In other
words, just open that form in design view and work on it
like any other form.

--
Marsh
MVP [MS Access]
.