A Timer Event solution

A Timer Event solution

am 15.11.2007 16:46:53 von Salad

This was an interesting problem. I open a form, CalledForm.

When a record is presented in CalledForm I needed to check the status of
something. If the status is met, I needed to present DialogForm prior
to allowing access to the record in CalledForm. So in the OnCurrent
event of CalledForm I had
If Status Then Docmd.Openform "DialogForm",,,,,acDialog

Worked fine. Later, I was asked to provide a command button in
DialogForm that would call/open "TasksForm" before going back to
CalledForm. This presented a dilemma since "TasksForm" called other
forms as well. And DialogForm was a modal form at this point. That
would mean I'd need to open TasksForm and any other forms it opened as
dialog as well or else they'd be hidden behind DialogForm.

I thought, "No Biggee", I'll set DialogForm's visible status to False
and return control to CalledForm and open the new TasksForm.
If Status then
Docmd.Openform "DialogForm"
If IsLoaded("DialogForm")
Docmd.close "DialogForm"
Docmd.Openform "TasksForm"
Endif
Endif

Didn't work. Why?
OnCurrent->OpenDialogForm->OnCurrent->OpenTaskForm->OnCurren t

This opened TasksForm but control was returned back to the OnCurrent
event of CalledForm and then CalledForm was the current object and
TasksForm was hidden behind it, just like it would have been if I had
called TaskForm from DialogForm.

How I solved it. I modified my last lines of the OnCurrent event to be
'on current event
If Status Then
Me.TimerInterval = 1
End If

By setting the TimerInterval to 1 in the OnCurrent event it permited the
OnCurrent event to complete. A millisecond later and the timer event
would fire.

My code for the Timer was
Private Sub Form_Timer()
Me.TimerInterval = 0 'stop the timer
ProcessSomething
End Sub

You may never need to do something like this. But if you get trapped by
events needing to complete and inhibiting what you want displayed,
this will work like a champ.

Dirty Dancing
http://www.youtube.com/watch?v=Hy1YF54rZZM

Re: A Timer Event solution

am 16.11.2007 05:20:58 von Tom van Stiphout

On Thu, 15 Nov 2007 07:46:53 -0800, Salad wrote:

When you set a modal form's .Visible=False, it will fall out of the
modal loop. That's by design, and can be very handy.

-Tom.



>This was an interesting problem. I open a form, CalledForm.
>
>When a record is presented in CalledForm I needed to check the status of
>something. If the status is met, I needed to present DialogForm prior
>to allowing access to the record in CalledForm. So in the OnCurrent
>event of CalledForm I had
> If Status Then Docmd.Openform "DialogForm",,,,,acDialog
>
>Worked fine. Later, I was asked to provide a command button in
>DialogForm that would call/open "TasksForm" before going back to
>CalledForm. This presented a dilemma since "TasksForm" called other
>forms as well. And DialogForm was a modal form at this point. That
>would mean I'd need to open TasksForm and any other forms it opened as
>dialog as well or else they'd be hidden behind DialogForm.
>
>I thought, "No Biggee", I'll set DialogForm's visible status to False
>and return control to CalledForm and open the new TasksForm.
> If Status then
> Docmd.Openform "DialogForm"
> If IsLoaded("DialogForm")
> Docmd.close "DialogForm"
> Docmd.Openform "TasksForm"
> Endif
> Endif
>
>Didn't work. Why?
>OnCurrent->OpenDialogForm->OnCurrent->OpenTaskForm->OnCurre nt
>
>This opened TasksForm but control was returned back to the OnCurrent
>event of CalledForm and then CalledForm was the current object and
>TasksForm was hidden behind it, just like it would have been if I had
>called TaskForm from DialogForm.
>
>How I solved it. I modified my last lines of the OnCurrent event to be
> 'on current event
> If Status Then
> Me.TimerInterval = 1
> End If
>
>By setting the TimerInterval to 1 in the OnCurrent event it permited the
>OnCurrent event to complete. A millisecond later and the timer event
>would fire.
>
>My code for the Timer was
> Private Sub Form_Timer()
> Me.TimerInterval = 0 'stop the timer
> ProcessSomething
> End Sub
>
>You may never need to do something like this. But if you get trapped by
> events needing to complete and inhibiting what you want displayed,
>this will work like a champ.
>
>Dirty Dancing
>http://www.youtube.com/watch?v=Hy1YF54rZZM
>
>
>
>
>
>

Re: A Timer Event solution

am 16.11.2007 14:34:50 von Salad

Tom van Stiphout wrote:
> On Thu, 15 Nov 2007 07:46:53 -0800, Salad wrote:
>
> When you set a modal form's .Visible=False, it will fall out of the
> modal loop. That's by design, and can be very handy.
>
> -Tom.

Yes it is.

I did that and opened the new form but the OnCurrent event had not
finished in the original calling form. Thus the new non-modal form
opened but the rest of the OnCurrent event code executed and then the
original calling form became the selected object instead of the form I
had just opened. It was an interesting exercise.



>
>
>
>
>>This was an interesting problem. I open a form, CalledForm.
>>
>>When a record is presented in CalledForm I needed to check the status of
>>something. If the status is met, I needed to present DialogForm prior
>>to allowing access to the record in CalledForm. So in the OnCurrent
>>event of CalledForm I had
>> If Status Then Docmd.Openform "DialogForm",,,,,acDialog
>>
>>Worked fine. Later, I was asked to provide a command button in
>>DialogForm that would call/open "TasksForm" before going back to
>>CalledForm. This presented a dilemma since "TasksForm" called other
>>forms as well. And DialogForm was a modal form at this point. That
>>would mean I'd need to open TasksForm and any other forms it opened as
>>dialog as well or else they'd be hidden behind DialogForm.
>>
>>I thought, "No Biggee", I'll set DialogForm's visible status to False
>>and return control to CalledForm and open the new TasksForm.
>> If Status then
>> Docmd.Openform "DialogForm"
>> If IsLoaded("DialogForm")
>> Docmd.close "DialogForm"
>> Docmd.Openform "TasksForm"
>> Endif
>> Endif
>>
>>Didn't work. Why?
>>OnCurrent->OpenDialogForm->OnCurrent->OpenTaskForm->OnCurr ent
>>
>>This opened TasksForm but control was returned back to the OnCurrent
>>event of CalledForm and then CalledForm was the current object and
>>TasksForm was hidden behind it, just like it would have been if I had
>>called TaskForm from DialogForm.
>>
>>How I solved it. I modified my last lines of the OnCurrent event to be
>> 'on current event
>> If Status Then
>> Me.TimerInterval = 1
>> End If
>>
>>By setting the TimerInterval to 1 in the OnCurrent event it permited the
>>OnCurrent event to complete. A millisecond later and the timer event
>>would fire.
>>
>>My code for the Timer was
>> Private Sub Form_Timer()
>> Me.TimerInterval = 0 'stop the timer
>> ProcessSomething
>> End Sub
>>
>>You may never need to do something like this. But if you get trapped by
>> events needing to complete and inhibiting what you want displayed,
>>this will work like a champ.
>>
>>Dirty Dancing
>>http://www.youtube.com/watch?v=Hy1YF54rZZM
>>
>>
>>
>>
>>
>>