Programmatically navigating form to New Record

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
 
D

Dale Fye

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
 
R

riyaz.mansoor

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
 
D

Dirk Goldgar

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).
 

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

Top