force a subform current event from main form

G

Guest

I seem unable to force a subform's current event from the main form under all
circumstances...

The subform is a continuous form and I need to be able to force the current
event for the subform from within the vb of the main form. Most of the time
standard techniques of .findfirst/.movefirst etc. do the job but sometimes,
especially when the subform's current record is the record that I need to
force the current event for, findfirst etc doesn't work, e.g.
me.subform.form.recordset.findfirst "seq = 3" won't force a current event if
the record where seq=3 is the current record.

I tried requery followed by findfirst which works for every record except
the first record. I have also tried move and absoluteposition but again,
these don't work when the current record is the one that I want to force a
current event for.

Incidentally it seems that, contrary to help pages, requery does not set the
current record to the first record - found this out by attempting to assign
one of the recordset's fields to a variable after requery and got the 'no
current record' error.
 
A

Allen Browne

I do not understand what you are trying to do (so I probably should not try
to answer.)

The Current event is triggered by Access when a form changes record. You do
not cause the event.

With code in the Current event, it is very easy to trigger problems. If you
are doing anything that assigns a value to a bound control, you are likely
to cause concurrency issues, spurious records, unnecessary writes, increased
network traffic, and other issues. I shudder to think what might be
happening in this event.

If you want to trigger the code in the event (not the event itself), you can
remove the "Private" keyword from the event declaration, and then use:
Call Form_Form2.Form_Current
where "Form2" represents the name of the form in the subform control.

A Requery causes the form to reload all records. That means the form's
current record after a Requery will be the same as the record that would be
shown if the form had just loaded for the first time (which could reasonably
be called the form's "first" record.) Those comments apply to a form that
has a table, query, or SQL string as its RecordSource: I am not clear
whether you are attempting to set the Recordset property of a subform, which
is not going to be very successful if the subform control has anything in
its LinkMasterFields/LinkChildFields, since Access will reload it when the
object(s) named in LinkMasterFields change value.
 
G

Guest

Not much is done in the current event, mainly enabling/disabling command
buttons depending on the data in the current record.

The problems I am having are rooted in some of the main form's (bound)
controls which, when altered, need to make changes to all of the records in
the subform. When these changes occur, sometimes the subform's current event
is triggered for the current record and sometimes it isn't, which means that
the subform command buttons are not correctly disabled/enabled according to
data in the current record. So when this happens I would like to be able to
artificially trigger the subform's current event from the main form's code.

Calling the current event procedure explicitly by the method you have given
me may help me to overcome my problems but without experimentation I am not
sure. I guess if I call it manually I'll have to prevent the automatic call
by temporarily removing the subform's OnCurrent property.

As part of my experimentation, and I have verified this again before posting
this reply, if I use F8 to execute a subform requery within the main form's
code, the next piece of code to be executed is the subform's current event,
if I continue to use F8 and execute (for example) var = Recordset!fld, I get
error 3021 (no current record) even though the subform has a recordcount of
0. This requery behaviour is not part of my problem, it is just something I
noticed as being inconsistent with help pages whilst trying to solve my real
problems.
 
J

John Griffiths

"The problems I am having are rooted in some of the main form's (bound)
controls which, when altered, need to make changes to all of the records in
the subform. When these changes occur, sometimes the subform's current event
is triggered for the current record and sometimes it isn't, which means that
the subform command buttons are not correctly disabled/enabled according to
data in the current record. So when this happens I would like to be able to
artificially trigger the subform's current event from the main form's code."

The sub form is bound to the values in the db not any other form.

Which means that :-

you have to save the values in the main form if you want to see the values
in the sub form via OnCurrent.
(Recomended)

or :-

if the sub form can only be used as part of the main form using Me.Parent.
(Not Recomended)

Regards John
 
G

Guest

Sorry John I think you have misunderstood, I mentioned that the controls were
bound only to try and be informative. The controls are bound to main form
data as opposed to unbound from any data, e.g. one of the mainform controls
is a combo which when altered needs to cause deletion of all existing subform
records and initialize the subform with a completely new set of records with
completely different data. I did not mean to imply that any of the main form
controls were in some way bound to the subform. Another of the main form
controls is a date which when altered needs to alter information on some or
possibly all of the subform records.
 
J

John Griffiths

In the LinkMasterFields/LinkChildFields properties you have a need to link
to mainform combo to the primary key of the subform record source.
See the answer from Allen Browne earlier.


Stop talking technical - talk specifics -what real world problem are you
trying to solve?

Regards John
 
G

Guest

What I want is technical help, which is why I am phrasing my problem
technically. I do not need any help with designing my application. If you do
not understand the technical problem that I have then I am sorry for my
inadequate explanations. There was no need for you to be rude. I have no need
for you to monitor or respond to this thread any more. If it takes me days to
find a solution myself I'd rather that than trouble you further.
 
J

John Griffiths

No problem.

Technical language is context sensitive by definition,
stepping back to an English description should help in mutual understanding.


Keep on keeping on - John
 
G

Guest

Hi Tricky

I've been searching for a solution to a similar problem. Do you get this
resolved?

Cheers
 

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