IsSubform....?

  • Thread starter Thread starter ALESSANDRO Baraldi
  • Start date Start date
A

ALESSANDRO Baraldi

Good evening.

How can i know if form is SubForm passing
only Form.Name to the external Function.

I nned it in a Form wich can be opened by many Form or SubForm
and i use OpenArgs property to pass to MyForm the Calling_Form.
When i close MyForm i need to execute Requery of the calling Form
so i need to check it to write good Syntax.

In this way i can't use Forms("FormName").Parent because is not
allowed if is subForm, and the errore retrive is not significant....!

Is wrong.....?
Have i made a mistake.....?

Thanks
 
There are two ways:

First, the name of the subform(Me.Name) is not a part of
the Forms Collection. Use the IsSubForm function below to
check.

Also, if you trap the error generated by Me.Parent, you
will know.

'Air Code

Public Function IsSubForm(strFormName as String) as Boolean
On Error Resume Next
Dim strParent As String
strParent = Forms(strFormName).Name
IsSubForm = Err.Number <> 0
End Function
 
Chris said:
There are two ways:

First, the name of the subform(Me.Name) is not a part of
the Forms Collection. Use the IsSubForm function below to
check.

I use Me.Name to pass by OpenArgs the Name, is correct because
i OPEN the NewForm from the SubForm.......so how can i Pass it !!!!

Also, if you trap the error generated by Me.Parent, you
will know.

'Air Code

Public Function IsSubForm(strFormName as String) as Boolean
On Error Resume Next
Dim strParent As String
strParent = Forms(strFormName).Name
IsSubForm = Err.Number <> 0
End Function

This code do not give right value if the Form is Close....!!
So before check i need to check if Form is Open....!!!

@Alex.
 
How can i know if form is SubForm passing
only Form.Name to the external Function.

I nned it in a Form wich can be opened by many Form or SubForm
and i use OpenArgs property to pass to MyForm the Calling_Form.
When i close MyForm i need to execute Requery of the calling Form
so i need to check it to write good Syntax.

In this way i can't use Forms("FormName").Parent because is not
allowed if is subForm, and the errore retrive is not significant....!

If you open the second form passing the "acDialog" argument to the mode
parameter of the OpenForm method (causing the form to opened in modal mode), the
code in the calling form will pause. Then simply add a line of code following
the OpenForm command with the "Requery" command. In this scenario, you need not
pass the name of the form via OpenArgs because the calling form will take care
of the requery:

'***EXAMPLE START
'Open the form modal
DoCmd.OpenForm "MyCalledFormName", , , , , acDialog
'The next line will run after "MyCalledFormName" closes
Me.Requery
'***EXAMPLE END
 
Bruce M. Thompson said:
If you open the second form passing the "acDialog" argument to the mode
parameter of the OpenForm method (causing the form to opened in modal mode), the
code in the calling form will pause. Then simply add a line of code following
the OpenForm command with the "Requery" command. In this scenario, you need not
pass the name of the form via OpenArgs because the calling form will take care
of the requery:

'***EXAMPLE START
'Open the form modal
DoCmd.OpenForm "MyCalledFormName", , , , , acDialog
'The next line will run after "MyCalledFormName" closes
Me.Requery
'***EXAMPLE END


Yes, i just do it in this way, i think i'll can do in a better
way....!!!
Thanks again.
Alessandro.
 
ALESSANDRO Baraldi said:
Good evening.

How can i know if form is SubForm passing
only Form.Name to the external Function.

I nned it in a Form wich can be opened by many Form or SubForm
and i use OpenArgs property to pass to MyForm the Calling_Form.
When i close MyForm i need to execute Requery of the calling Form
so i need to check it to write good Syntax.

In this way i can't use Forms("FormName").Parent because is not
allowed if is subForm, and the errore retrive is not significant....!

Is wrong.....?
Have i made a mistake.....?

Thanks

Hmm, the only other approach I can think of at the moment is to use a
global variable of type Form to pass a reference to the form object
between the calling routine and the called routine. It's a bit fragile,
but suppose you had a global variable defined in a standard module:

Dim gfrm_PassedForm As Form

Then the calling routine could do this:

Set gfrm_PassedForm = Me
DoCmd.OpenForm "MyForm"

Form "MyForm" would then have code like this:

'----- start of module for form MyForm -----
Dim mfrmPassed As Form

Private Sub Form_Open(Cancel As Integer)

' Capture current global form object,
' then clear the global object.

Set mfrmPassed = gfrm_PassedForm
Set gfrm_PassedForm = Nothing

End Sub

Private Sub Form_Close()

If IsObject(mfrmPassed) Then
mfrmPassed.Requery
Set mfrmPassed = Nothing
End If

End Sub
'----- end of module code -----
 
Dirk Goldgar said:
Hmm, the only other approach I can think of at the moment is to use a
global variable of type Form to pass a reference to the form object
between the calling routine and the called routine. It's a bit fragile,
but suppose you had a global variable defined in a standard module:

Dim gfrm_PassedForm As Form

Then the calling routine could do this:

Set gfrm_PassedForm = Me
DoCmd.OpenForm "MyForm"

Form "MyForm" would then have code like this:

'----- start of module for form MyForm -----
Dim mfrmPassed As Form

Private Sub Form_Open(Cancel As Integer)

' Capture current global form object,
' then clear the global object.

Set mfrmPassed = gfrm_PassedForm
Set gfrm_PassedForm = Nothing

End Sub

Private Sub Form_Close()

If IsObject(mfrmPassed) Then
mfrmPassed.Requery
Set mfrmPassed = Nothing
End If

End Sub
'----- end of module code -----

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

(please reply to the newsgroup)


Hi.
You check and resolve my problem.
Using a Form variable type in this way i bypass
any Sub/Form difficulties.....!!
100%
Very interesting and simple....!

many thanks.
Alessandro.
 
Back
Top