Form_Activate not being triggered

G

garth.kirkwood

I have a Main form with a subform containing related records I have a
double click event in the subform to open another form to view the
records in their own form. The problem is the Form_Activate procedure
on the form that open is not running. I am opening the new form via a
DoCmd.Open form.

Could someone explain to me how to get the Form_Activate to trigger?
The end result I am after is that the Form_Activate is to find the
record that was selected in my subform and then move to that record in
the new form that is opened.
 
R

Rob Parker

The Activate event of the form which is opening will occur after the Open
and Load events, and it will occur when the form is opened via a
DoCmd.OpenForm statement. I can't tell you why it's not doing what you
want; maybe the problem with that is in the code you are running in the
Activate event itself. You can check that it is triggered by simply adding
a Debug.Print or MsgBox statement in its code.

That said, I would also suggest that the Activate event is not a good choice
for doing what you want, since it occurs not only when you open the form,
but also whenever you reselect the window of that form after moving to
another form/window. The usual method of opening a new form to display a
record from its recordsource related to the current record is to use a Where
parameter in the DoCmd.OpenForm statement to open the new form displaying
the record you have selected (normally via the primary key field of the
current record). Something like:
DoCmd.OpenForm "NewFormName", , , "PrimaryKeyFieldName = " &
Me.PrimaryKeyFieldName
if the primary key field is a number, or:
DoCmd.OpenForm "NewFormName", , , "PrimaryKeyFieldName = '" &
Me.PrimaryKeyFieldName & "'"
if the primary key field is a text field. Expanded for clarity, that is:
DoCmd.OpenForm "NewFormName", , , "PrimaryKeyFieldName = ' " &
Me.PrimaryKeyFieldName & " ' "
and if the field may contain a single-quote character, replace the
single-quote with a pair of double-quote characters.

HTH,

Rob
 
J

JonWayn

The only thing I can suggest is that: if you are sure that you created the
Activate event, then open the form in design view and ensure that it is
connected to the event. Do this by selecting the form in the property sheet,
click the Events tab, ensure that the OnActivate event has [Event Procedure]
selected next to it. Sometimes this blanks out for whatever reason and
therefore doesnt get triggered.

On the other note, what I do when I have a similar need to transfer data
from 1 form to one I am about to open is use the OpenArgs argument to the
OpenForm method. Once the newly opened form opens, it uses this argument to
initialize itself, in this case, locate the first record.
 
G

garth.kirkwood

Thanks all for the great pointers and Jon I had already checked the
OnEvent to ensure that is was "connected". I know that the Activate
event was not occuring as I had a break point set in the Sub and it
was not triggered.

I looked at what Rob suggested but the problem with using this method
was that it only opens the record specified in the OpenForm clause
which is not what I needed.

I have got around my problem by moving the FindRecord command to the
command that opens the form, although I would really like to know why
my Activate command is not running. I copied the Form_Activate event
from a MS Database and it works in that database so I don't know what
is different in mine.
 
R

Rob Parker

The use of a Where clause in the DoCmd.OpenForm statement usually is used to
limit the new form to displaying a single record, but it does not have to be
so. If you build your Where clause to show the desired subset of records
from the new form's datasource, you can display multiple records in the new
form. However, the new form will still, by default, show the first matching
record, which may not be what you want - you may need to move to a
particular record via code.

Again, HTH,

Rob
 
G

garth.kirkwood

I am trying to use the Form_Activate in another section of my code and
I still can't get it to work. I have another DB (supplied by MS) and
there one is working.

AH HA!!!! I worked it out. The form I was opening was set to POP-UP so
in essence the main form opening the "pop-up" never was de-activated.
A trick for young players.
 

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