Programmatically navigating form to New Record

  • Thread starter Thread starter riyaz.mansoor
  • Start date Start date
R

riyaz.mansoor

Hi

I have a mainform and with a subform (NOT linked). I'm trying to
implement mainform navigation when the subform has focus. eg: When a
control on the subform has focus, pressing PageUp should move one
record up on the main form.

I have done this using mainform.Recordset.MoveFirst (MoveNext,
MovePrevious, MoveLast). This all works fine.

Problem is that when on the last record - pressing PageDown should
take me to a new record on the main form.
Docmd.GotoRecord ... acNext ----- is not suitable because my mainform
itself is contained in a "master" form (mainform is also a subform).

Any way i can programmatically put a subform into new record if the
subform does NOT have the focus?

Riyaz
 
Riyaz,

Generally, a subform is linked to the main form via at least one field. I
usually do this by setting a reference to a control on the main form in the
query that is the Record Source for the subform. Then, in the main forms
Current event, I requery ths subform.

If you add some code to your PgDown to insert a new record into the main
form, and also insert a record into your subform with a matching ID value to
the one on the main form, you could do this. Then, after you have done the
above, you could go to the main forms last record.

Otherwise, when you go to the new record on your main form, the subform will
not have any valid records.

HTH
Dale
 
Hi
Generally, a subform is linked to the main form via at least one field. I
usually do this by setting a reference to a control on the main form in the
query that is the Record Source for the subform. Then, in the main forms
Current event, I requery ths subform.

As I said, this subform is NOT linked to the main-form.
If you add some code to your PgDown to insert a new record into the main
form, and also insert a record into your subform with a matching ID value to
the one on the main form, you could do this. Then, after you have done the
above, you could go to the main forms last record.

Otherwise, when you go to the new record on your main form, the subform will
not have any valid records.

I'm not sure how this relates.

Riyaz
 
In
Hi

I have a mainform and with a subform (NOT linked). I'm trying to
implement mainform navigation when the subform has focus. eg: When a
control on the subform has focus, pressing PageUp should move one
record up on the main form.

I have done this using mainform.Recordset.MoveFirst (MoveNext,
MovePrevious, MoveLast). This all works fine.

Problem is that when on the last record - pressing PageDown should
take me to a new record on the main form.
Docmd.GotoRecord ... acNext ----- is not suitable because my mainform
itself is contained in a "master" form (mainform is also a subform).

Any way i can programmatically put a subform into new record if the
subform does NOT have the focus?

You might try:

Me.Parent.Recordset.AddNew

(assuming this code is executing the subform for which mainform is the
parent).
 
Back
Top