Screen.PreviousForm

M

Max

Am opening the same form (PtsForm) from a command button on two different
forms (MasterForm and EditForm). Would like to set a value based on which
form opened PtsForm. Tried using screen.activeform but with no luck. Is there
a way to reference the previous form?

Thanks in advance.
 
D

Dirk Goldgar

Max said:
Am opening the same form (PtsForm) from a command button on two different
forms (MasterForm and EditForm). Would like to set a value based on which
form opened PtsForm. Tried using screen.activeform but with no luck. Is
there
a way to reference the previous form?


Where was it that you were checking Screen.ActiveForm? in the Open event of
a form, that form is not yet the "active form". The form that was active
before that form was opened is still the active form. So you should be able
to check Screen.ActiveForm in the Open event of PtsForm and see which form
opened it. Of course you have to allow for the possibility that some other
form opened it, or that no other form was open (e.g., when opening the form
from the database window. For example:

Private Sub Form_Open(Cancel As Integer)

Dim strCallingForm As String

On Error Resume Next
strCallingForm = Screen.ActiveForm.Name

Select Case strCallingForm

Case "MasterForm"
' do something

Case "EditForm"
' do something else

Case Else
' none of the above; what to do?

End Select

End Sub


If for some reason this doesn't work for you, you can pass the name of the
calling form to the called form via OpenArgs.
 
M

Max

Worked like a charm - you do magic! Thanks.

Dirk Goldgar said:
Where was it that you were checking Screen.ActiveForm? in the Open event of
a form, that form is not yet the "active form". The form that was active
before that form was opened is still the active form. So you should be able
to check Screen.ActiveForm in the Open event of PtsForm and see which form
opened it. Of course you have to allow for the possibility that some other
form opened it, or that no other form was open (e.g., when opening the form
from the database window. For example:

Private Sub Form_Open(Cancel As Integer)

Dim strCallingForm As String

On Error Resume Next
strCallingForm = Screen.ActiveForm.Name

Select Case strCallingForm

Case "MasterForm"
' do something

Case "EditForm"
' do something else

Case Else
' none of the above; what to do?

End Select

End Sub


If for some reason this doesn't work for you, you can pass the name of the
calling form to the called form via OpenArgs.


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dale Fye

Dirk,

It had never occurred to me that the new form was not the Active Form until
after it was opened. I've been passing the name of the calling form in the
OpenArgs argument for all these years.

I'll have to consider this for future use, although the developer needs to
add some error handling code to account for the instance where the form is
opened from the database window.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top