Open form from button on other form

J

Jan Pit

On Form01 I have a button with the command
DoCmd.OpenForm "Form02"
which normally works fine.

On Form02 in the OnOpen event is the line:
DoCmd.GotoRec acGoto, 12

If I open Form02 from the Database window there is still no problem and the
Form displays record 12.

But if I use the button on Form01 to open Form02 then I get the following
error:
"Runtime Error 2499: You can't use the GotoRecord action or method on an
object in Design View"
I am not in Design mode as far as I can see. I just want to display a
particular record on Form02, by clicking a button on Form01.

Access 2000. The is no filter (and there should not be). Instead of
Gotorecord I may want to use Findrecord, but now that has the same problem.

Any ideas?????

TIA,

+ Jan Pit +
Botswana
 
A

Allen Browne

Jan, try the Load event instead of the Open event.

The Open event occurs before the data is loaded (the Load event).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jan Pit said:
On Form01 I have a button with the command
DoCmd.OpenForm "Form02"
which normally works fine.

On Form02 in the OnOpen event is the line:
DoCmd.GotoRec acGoto, 12

If I open Form02 from the Database window there is still no problem and the
Form displays record 12.

But if I use the button on Form01 to open Form02 then I get the following
error:
"Runtime Error 2499: You can't use the GotoRecord action or method on an
object in Design View"
I am not in Design mode as far as I can see. I just want to display a
particular record on Form02, by clicking a button on Form01.

Access 2000. The is no filter (and there should not be). Instead of
Gotorecord I may want to use Findrecord, but now that has the same
problem.
 
J

Jan Pit

Thanks Allen.
In fact that did first not work neither. I had already tried OnActivate and
even OnCurrent (with as flag).
But your answer stimulated me to explore further.

The problem was that I closed Form01 in the OnOpen (or OnLoad etc.) event.
When you do that BEFORE the GotoRecord, the error occurs, but if you close
right AFTER the GotoRecord then thing are fine.
Pretty curious, but we keep learning.

Thanks again

+ Jan +
 

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