Calling a Second Form and Returning to Original

  • Thread starter Thread starter Gene
  • Start date Start date
G

Gene

Hi and Happy New Year. I have modules that multiple
forms "call" for calculations. I am trying to take
information from one form, call up another form which
requires input and calculations, and after that input,
return to the original form and continue where the "call"
left off. The code goes something like this:

If vMissingData > 1 then goto AddData
AddData:
If MsgBox("You need Data", vbOKOnly) then
CALL AddMissingData(ID,StartDate)
GoToContinue
Endif
So if some data is missing, then I go to the label
AddData which informs the end user through a message box
that they have missing data. When they click OK, the
program calls a module with the arguments noted. That
module utilizes a standard ADD DATA form, which requires
input and clicking a command button and then the data is
appended to a table of data points. I then want to
return to the original form, go back to the point where
the missing data points were noted (labeled as
Continue: ), and then proceed.
After that long winded explanation, the problem is that
the first form won't wait for the "called" form to be
executed. It bounces back immediately and causes all
types of confusion.
So, is there anyway to call a second from from the
original, have the original form on hold until the second
form has its data entered and executed, and then return
to the original form to be completed? I would like to
avoid a subform, because I prefer having standardized
code that is usable by many forms. BUT, if that is the
only route, I will do it. Any suggestions?
Thanks.
Gene
 
Have you looked at using a Function that accepts the
needed inputs, and returns whatever parameter you need?
 
The form I need to call requires mulitiple, sequential
entries, so a function would become very complex, but I
will take a look. Maybe I just need to rebuild the code
into the original form, but it seems a shame to duplicate
that much space. Thanks.
Gene
 
Gene,

Open the NorthWind modules and find the IsLoaded function. You'll need this
below ---

Put this code in the Click event of a command button on the first form:

DoCmd.OpenForm "NameOfSecondForm",,,,,acDialog
If IsLoaded("NameOfSecondForm") Then

<<Do What You Want With The Data From Second Form>>
<<You Can Refer To Data In Second Form Like This:>>
<<Me!NameOfFieldInForm1 = Forms!NameOfSecondForm!FieldNameInSecondForm>>

DoCmd.Close acForm "NameOfSecondForm"
End If
 
I use this a lot when creating general purpose Find form & generally pass either the form (resource expensive) or the name of the form doing the calling. If you are calling another form pass the name of the calling form as a parameter when opening the second form.
The second form is being 'jumped through' can be prevented by opening it as a Dialo
e
docmd.OpenForm "SecondFormName",acNormal,,,,acDialog,me.Nam
Using the acDialog will mean that the second form MUST be closed before code continues in the calling routin
The Me.Name sends the name of the calling form to the second form. In the second form you can now refer t
Forms(Me.OpenArgs
(Do not forget to check whether the OpenArgs have been set as the second form may have been opened manually and thus there are no openarg
HT
Terr
 
-----Original Message-----

After that long winded explanation, the problem is that
the first form won't wait for the "called" form to be
executed. It bounces back immediately and causes all
types of confusion.
So, is there anyway to call a second from from the
original, have the original form on hold until the second
form has its data entered and executed, and then return
to the original form to be completed? I would like to
avoid a subform, because I prefer having standardized
code that is usable by many forms. BUT, if that is the
only route, I will do it. Any suggestions?
Thanks.
Gene

.
Hi Gene, when you use the line docmd.openform the
WindowMode setting acDialog has the effect that you
require.

Luck
Jonathan
 
Back
Top