Wait fr Form to Close

  • Thread starter Thread starter Steve Haack
  • Start date Start date
S

Steve Haack

I have a form, that a user inputs a ProductCode into and then clicks the Find
button. In the code for btnFind_OnClick, I call a seperate function to look
the ProductCode up in a table and see if it exists. This part works fine.

If it does not exist, I retrun a result back that it was not found. I then
ask the user if they want to create a new record for the product.

When they say yes, then I call another function called CreateProduct which
opens a frmProductInfornation form with a new record.

The problem I am having, is that once the new form is opened, the
CreateProduct then returns back to the btnFind_OnClick sub, without waiting
for the user to finish adding all the details in the frmProductInformation
and saving (and closing) the ProductInformation form.

How can I get this CreateProduct function to wait for the form to close
before contuing (and thus returning to the original calling sub)?

Thanks,
Steve
 
Hi Steve,
When a form is opened with the window mode set to acDialog, all other forms
become inactive until that form is closed.

So your code needs to be like:
DoCmd.OpenForm, "frmProductInfornation", , , , , acDialog


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Just watch the typo with that code - one too many commas after OpenForm

Here is the correct syntax:
DoCmd.OpenForm "frmProductInfornation", , , , , acDialog

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Just watch the typo with that code - one too many commas after OpenForm

Here is the correct syntax:
DoCmd.OpenForm "frmProductInfornation", , , , , acDialog

or to avoid counting commas...

DoCmd.OpenForm "frmProductInformation", WindowMode := acDialog

Note that it's colon-equals, not just equals.
 
Thanks for the replies. I had already tried that, and I believe that it works
when you are calling one from from within another form's code.

However, the code in my form is calling a function which is in a code
module, and then that function is loading the second form.

What I need is a way for that function to wait for the second form to close,
before returning back to the code in the original form.

Does that make sense?
 
Steve,
that function in the module needs to call the second form with the acDialog
argument.

When the user closes the form open in acDialog, access will go back to that
function in the module and resume from where it left off.

acDialog is the way to stop all other code from running while that second
form is open.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Thanks for the replies. I had already tried that, and I believe that it works
when you are calling one from from within another form's code.

However, the code in my form is calling a function which is in a code
module, and then that function is loading the second form.

What I need is a way for that function to wait for the second form to close,
before returning back to the code in the original form.

Does that make sense?

Yes. You're opening the second form from code (your module's code); if you
open it in dialog view, everything stops until it's been either closed or made
invisible. Therefore the code will stop (in your module) without returning to
the first form.

Just open the second form in dialog mode. It works no matter where the code
is, it doesn't have to be code in a form.
 
Steve Haack said:
How can I get this CreateProduct function to wait for the form to close
before contuing (and thus returning to the original calling sub)?

Actually, a better way is to have the form that closes can call some code
that you want to run AFTER the user is done with the form...

However, I explain in detail how you can open up a form, enter data, and
"return" the values of that form to the call sub....

http://www.members.shaw.ca/AlbertKallal/Dialog/Index.html
 
OK. So this is really getting strange.

When I use this command:
DoCmd.OpenForm "frmViewEditProductInformation", acDialog, , , acFormAdd

Then it opens the form with a new record, but the code DOES NOT wait for the
form to close bfore continuing.

When I use this command:
DoCmd.OpenForm "frmViewEditProductInformation", WindowMode:=acNormal,
DataMode:=acFormAdd

Then it opens the form, and the code waits, but it DOES NOT give me a new
record.

The Form properties are set to Pop Up and Modal both as Yes, and Data Entry
as Yes also.

Any Ideas now?

Thanks,
Steve
 
Steve,
when you use DoCmd.OpenForm
you must put the commas and the code in the correct spots or it won't work.

Instead of
DoCmd.OpenForm "frmViewEditProductInformation", acDialog, , , acFormAdd<

Try
DoCmd.OpenForm "frmViewEditProductInformation", , , , acFormAdd, acDialog

The commas are place holders. Check vba help for DoCmd.OpenForm to get more
instructions on how to use this method.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
DoCmd.OpenForm "frmViewEditProductInformation", , , , acFormAdd, acDialog

The commas are place holders. Check vba help for DoCmd.OpenForm to get more
instructions on how to use this method.

Good point, and yes that would be the problem!

I actually get crosseyed trying to count all the commas, so I'll usually use
the alternative format, explicitly specifying the parameters:

DoCmd.OpenForm "frmViewEditProductInformation", _
DataMode:=acFormAdd, _
WindowMode:=acDialog
 
Back
Top