Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question Similar to "Macro Too Fast"

Status
Not open for further replies.

Paul7905

MIS
Jun 29, 2000
205
US
I have a question similar to one of todays posts where someone needed to get Access to wait a while for another process to complete.

Here is my dilema:

I have a form (let's call it Form1) with a command button on it which runs some VBA code in the on the click event.

In the middle of this code, I may determine that it is necessary to open another form (Form2) so that the user can enter some data to create a new record.

I need a way, in the Form1 code, to wait for the activity in Form2 to complete and then resume the code.

In other words, when the code in Form1 determines it needs to open Form2, it can open Form2 and then monitor whether Form2 is open and when it determines Form2 is closed, the Form1 code will resume where it left off.


The timer solution alone will not work unless I can somehow in the Form1 code do some sort of check every X seconds to see if Form2 is open or not and then Resume processing when it determines Form2 has been closed by the User.

Has anyone had to do something similar and have a solution?

Thanks !

Paul
 
Hi Paul,

I've never had to do that, but the simplest way I can think to do it (and the easiest to maintain) would be to split your code into 2 functions with the break right where you would need the form to appear. Then if you don't need the form the first function can call the second and continue like nothing ever happened, but if you do need the form you can open the form at the end of the first part and not call the second part until the "OnClose" event of your form.

Hope this helps,

Kyle ::)
 
Kyle,
just got this response from Jeff on the VBA coding forum (I just tried it in my vba code and it works great ! ):


Try this:

DoCmd.OpenForm "YourForm", , , , , acDialog

The acDialog is called the windowmode, in this case you are telling Access that the form you are opening must be closed before you continue to run the code in the calling form.

hth

Jeff Bridgham

 
Yeah, I just saw that about 2 minutes ago. Learn something new every day!
 
Jfisher

I tried this too and it works ! Caveat is that i had to put a loop in the Form1 code to call this function and a doevents statement.

i ran the system monitor with both solutions and noticed that using the function below (with the calling program loop to keep testing to see if the form is open) that the kernel (processor) runs at 100%.

using the acdialog method to open the form does not run the processor up at all.



Function fIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
fIsLoaded = True
End If
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top