Open a new form and closing the old form - a potential problem for referenced field?

R

Robert

I have two forms which are both popups. After the first one is displayed
the user clicks on the the listbox on the form and in the on click event the
second form is opened and the first form closes itself in succession..

DoCmd.OpenForm "secondform"
DoCmd.Close acForm,"firstform"

The thing is the query in the second form references the list box in the
first form for a value. So far it works fine in testing but I was concerned
whether the first form could close too fast before the second form is able
to excute its query which references the first form.

Robert
 
R

Rick Brandt

Robert said:
I have two forms which are both popups. After the first one is
displayed the user clicks on the the listbox on the form and in the
on click event the second form is opened and the first form closes
itself in succession..
DoCmd.OpenForm "secondform"
DoCmd.Close acForm,"firstform"

The thing is the query in the second form references the list box in
the first form for a value. So far it works fine in testing but I
was concerned whether the first form could close too fast before the
second form is able to excute its query which references the first
form.
Robert

You could use...

DoCmd.OpenForm "secondform"
Me.Visible = False

....and then use code in the second form to close the first. I'm pretty sure
that if you use the Load event that the query will have been done running by
that point. If not then the Timer event could be used.

Another alternative would be to leave the first form open but hidden. If you
close it and the user (or your code) tries to refresh or requery the second form
you will get an error. By leaving the first form open you avoid that. You
could then close the first form in the Close event of the second.
 
L

Linq Adams via AccessMonster.com

I don't think this will be a problem. The reference is already made and will
hold until the procedure, i.e. the first form closing and the query loading
the second form, is complete. This is true regardless of how many records are
retrieved by the query.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
R

Robert

I see what you are saying. The second form's query must start, not finish,
before the first form is closed. Is it even possible for the first form to
close before the second form starts its query? Would other users make a
difference?
 
R

Robert

Thanks.
Rick Brandt said:
You could use...

DoCmd.OpenForm "secondform"
Me.Visible = False

...and then use code in the second form to close the first. I'm pretty
sure that if you use the Load event that the query will have been done
running by that point. If not then the Timer event could be used.

Another alternative would be to leave the first form open but hidden. If
you close it and the user (or your code) tries to refresh or requery the
second form you will get an error. By leaving the first form open you
avoid that. You could then close the first form in the Close event of the
second.
 

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