Subform not open problem ?!?

  • Thread starter Thread starter David
  • Start date Start date
D

David

I had a series of forms that worked off command buttons,
the forms were opened by the command button being clicked.
Each form has a 'top', 'bottom' and 'exit' button in the
footer.

I decided to put these forms instead in a tabbed form, one
tab for each form. I added the forms as subforms one to
each tab.

The forms now show with the data when each tab is pressed.
However, when I click on the form command buttons to
navigate to the top and bottom records, I get a
message 'form not open'.

The forms were originally opened by command buttons
running 'Docmd.openform "formname",,,,acFormEdit'

The failing statements are:
'DoCmd.GoToRecord acDataForm, "formname", acFirst'
or
'DoCmd.GoToRecord acDataForm, "formname", acNewRec'
 
A subform is not open on its own....it's part of the main form in which it's
embedded. Thus, your old code will not work (as you've found out).

Instead of using DoCmd.OpenForm references to get to the subforms, you'll
need to use SetFocus commands to get to the subforms...and you need two of
them when going from a main form to a control on a subform.

Me.SubFormName.SetFocus
Me.SubFormName.Form.ControlName.SetFocus

In the above code SubFormName is the name of the subform control (the
control that holds the subform), not the name of the form that is being used
as the Source Object of that subform control.
 
Sorry, I missed one part....also eliminate the
acDataForm...so your statement will look like:

'DoCmd.GoToRecord , , acFirst'
 
Thanks. My subforms are just continouus forms that allow
editing and addition of new records. There are no controls
on there apart from the command buttons. How do I do
the 'gotorecord' operations for top and bottom?
I'm beginning to thinbk I should just go back to my
earlier approach as this seems very complex. But I hate
the user to have to click a tab then a command button to
open these forms.
 
Amazing... it works.... but why ?
-----Original Message-----
Sorry, I missed one part....also eliminate the
acDataForm...so your statement will look like:

'DoCmd.GoToRecord , , acFirst'

.
 
A subform must contain controls if it's displaying data. Data are displayed
in controls. Also, command buttons are controls.

To go to first or last records respectively:

Me.SubFormName.Form.Recordset.MoveFirst

or

Me.SubFormName.Form.Recordset.MoveLast
 
Back
Top