VBA execution control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Opening a modal form causes the code to stop until that
form closes, so you don't have to do anything else -- just
make certain the form you open is, as you note, "popup"
and "modal".

Larry Linson
Microsoft Access MVP
-----Original Message-----
Hi,

I have a series of modules in a database that I use
as 'Helper Functions' which I import as a reference into
other databases to provide common used functions. I would
like to use a form from the Helper Functions database to
send info into the referencing database but I cannot halt
the execution of the calling vb code in order to get data
from the form. The basic scenario is this:
1. User presses a button in Parent database
2. Form from the Helper Function database opens allowing
the user to make a choice. This form has Ok & Cancel
Buttons. 3. The user selects an option and presses
Ok/Cancel.
4. The selection made is returned to the Parent database.
5. The returned value is then used in further code.

Code is something like:
' in Parent database
Sub ShowUserChoice()
Dim thisValue as Variant
' Get The User's Input
thisValue = GetUserChoice()

' Use the User's Input
MsgBox "Selected: " & thisValue
End Sub

and

' in Helper Functions database
Function GetUserChoice() as Variant
DoCmd.OpenForm "User Choice Form"
**
GetUserChoice = GlobalReturnValue
End Function

The 'GlobalReturnValue' is a global variable (Variant)
that is assigned when the user presses Ok or Cancel in
the 'User Choice Form" until that point it is Null
I want to be able to pause at the point marked ** whilst
the user makes their choice and to resume when they have
pressed the Ok or Cancel button on the User Choice Form as
at present the code simply runs straight through and uses
the default Null for the GlobalReturnValue and I am unable
to do anything with it.
 
The problem is that it doesn't do this

The code in the Parent database continues to execute

The modal & popup form is in the Helper Database and that pauses execution fine, but the Parent database does not halt while the form is visible

I verify this by displaying a Message Box with the user's choice in it from the Parent database (as shown in the code example) and this appears immediately after the User Choice Form is displayed and before any choice is made

I need to find a way to halt the execution in the Parent database without using a Modal form as I want the form to be a generic one and not to have to write a new one every time I want to use the functionality

----- (e-mail address removed) wrote: ----

Opening a modal form causes the code to stop until that
form closes, so you don't have to do anything else -- just
make certain the form you open is, as you note, "popup"
and "modal"

Larry Linso
Microsoft Access MV
-----Original Message----
Hi
as 'Helper Functions' which I import as a reference into
other databases to provide common used functions. I would
like to use a form from the Helper Functions database to
send info into the referencing database but I cannot halt
the execution of the calling vb code in order to get data
from the form. The basic scenario is this
2. Form from the Helper Function database opens allowing
the user to make a choice. This form has Ok & Cancel
Buttons. 3. The user selects an option and presses
Ok/Cancel.
4. The selection made is returned to the Parent database
5. The returned value is then used in further code
' in Parent databas
Sub ShowUserChoice(
Dim thisValue as Varian
' Get The User's Inpu
thisValue = GetUserChoice(
MsgBox "Selected: " & thisValu
End Su
Function GetUserChoice() as Varian
DoCmd.OpenForm "User Choice Form
*
GetUserChoice = GlobalReturnValue
End Functio
that is assigned when the user presses Ok or Cancel in
the 'User Choice Form" until that point it is Nulthe user makes their choice and to resume when they have
pressed the Ok or Cancel button on the User Choice Form as
at present the code simply runs straight through and uses
the default Null for the GlobalReturnValue and I am unable
to do anything with it
 
Back
Top