Opening a form as datasheet and dialog will not pause code

R

roel.schreurs

I discovered some strange behaviour of Access XP. I have many times
used the possibility to open a form as a dialog and benefit from the
fact that execution of the code after the DoCmd.OpenForm statement will
pause and only resume after the form is closed or hidden.
Now, I want to do the same thing for a datasheet. Now, the code will
not pause.
To reproduce this behaviour, create two forms. The first one should get
to command buttons, each with its own click event handler, as follows:

Private Sub Command0_Click()
DoCmd.OpenForm "Form2", acNormal, , , , acDialog
MsgBox "Code resumes only after closing a form."
End Sub

Private Sub Command1_Click()
DoCmd.OpenForm "Form2", acFormDS, , , , acDialog
MsgBox "Code resumed directly after opening a datasheet."
End Sub

The second form does not need any code, just save it under the name
Form2. Open the first form and click one of the buttons. For the first
button, you'll need to close Form2 to see the message appear. When
clicking the second button, the message will follow immediately after
opening the form.

Does anybody know if there is some profound reason for this
distinction? Also, does anybody know a work-around to get the following
done:
I typically want to open the second form when a combobox on the first
form does not contain the correct choice for a user. The second form
allows the user to append the correct choice. After saving the data and
closing the form, I want to requery the combobox to allow the user to
choose the newly added value.
Of course, I could use the Activate event, but that will generate quite
a few redundant requeries.
 
J

J

Workaround:
Make your datasheet form a subform. Make the datasheet as big as
possible in the main form so that you can barely tell.

Sorry to hear about that bug, best of luck.
~J
 

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