replacing with a global variable name

  • Thread starter Thread starter LisaB
  • Start date Start date
L

LisaB

I am trying to get a call statement to work with a global name that will be
passed to the function. What is the correct syntax

This works if I use the actual form name
Call Me.[subtblGranteeContacts].Form.LockEdit

This does not work (trying to pass the form name through a global variable)
Call Me.[(GLBL_SubFormName)].Form.LockEdit
 
LisaB said:
I am trying to get a call statement to work with a global name that
will be passed to the function. What is the correct syntax

This works if I use the actual form name
Call Me.[subtblGranteeContacts].Form.LockEdit

This does not work (trying to pass the form name through a global
variable) Call Me.[(GLBL_SubFormName)].Form.LockEdit

Call Me(GLBL_SubFormName).Form.LockEdit
 
I tried it that way but got a runtime error 2465

Can't find the field 'name of the subform' referred to in your expression

I declared GLBL_subformName as string. should I declare it as a variant?

Dirk Goldgar said:
LisaB said:
I am trying to get a call statement to work with a global name that
will be passed to the function. What is the correct syntax

This works if I use the actual form name
Call Me.[subtblGranteeContacts].Form.LockEdit

This does not work (trying to pass the form name through a global
variable) Call Me.[(GLBL_SubFormName)].Form.LockEdit

Call Me(GLBL_SubFormName).Form.LockEdit

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

(please reply to the newsgroup)
 
also, the subform is not determined until the main form is loaded. I use
the following function

------------------------
Public Sub UpdateAppSource()
Dim strAbstractForm As String
Dim strStrategyArea As String
Dim strPhase As String

strStrategyArea = IIf(IsNull(Left(StrategyArea, 3)), "", Left(StrategyArea,
3))
strAbstractForm = ""
strPhase = ""

If (strStrategyArea = "CBA") Or (strStrategyArea = "CBO") Or
(strStrategyArea = "CCD") Then
If (PhaseID = 1) Or ((PhaseID = 2) And (Left(MTCID, 5) = "00100")) Then
strPhase = "PI"
End If
strAbstractForm = "subfrm" & strStrategyArea & "AbstractData" & strPhase
subfrmAbstractData.SourceObject = strAbstractForm
subfrmAbstractData.LinkChildFields = "GranteeActivityID"
subfrmAbstractData.LinkMasterFields = "GranteeActivityID"
Else
subfrmAbstractData.SourceObject = "frmBlank"
End If
GLBL_SubFormName = strAbstractForm

subfrmAbstractData.Requery
Me.Refresh

End Sub
--------------------------

Maybe the call should be CALL me.subfrmAbstractData.form.LockEdit ????

Dirk Goldgar said:
LisaB said:
I am trying to get a call statement to work with a global name that
will be passed to the function. What is the correct syntax

This works if I use the actual form name
Call Me.[subtblGranteeContacts].Form.LockEdit

This does not work (trying to pass the form name through a global
variable) Call Me.[(GLBL_SubFormName)].Form.LockEdit

Call Me(GLBL_SubFormName).Form.LockEdit

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

(please reply to the newsgroup)
 
Call Me(GLBL_SubFormName).Form.LockEdit

Note that your function "lockEdit" needs to be declared as public...and it
should work..
 
Yes, CALL me.subfrmAbstractData.form.LockEdit works (I don't know why)

LisaB said:
also, the subform is not determined until the main form is loaded. I use
the following function

------------------------
Public Sub UpdateAppSource()
Dim strAbstractForm As String
Dim strStrategyArea As String
Dim strPhase As String

strStrategyArea = IIf(IsNull(Left(StrategyArea, 3)), "", Left(StrategyArea,
3))
strAbstractForm = ""
strPhase = ""

If (strStrategyArea = "CBA") Or (strStrategyArea = "CBO") Or
(strStrategyArea = "CCD") Then
If (PhaseID = 1) Or ((PhaseID = 2) And (Left(MTCID, 5) = "00100")) Then
strPhase = "PI"
End If
strAbstractForm = "subfrm" & strStrategyArea & "AbstractData" & strPhase
subfrmAbstractData.SourceObject = strAbstractForm
subfrmAbstractData.LinkChildFields = "GranteeActivityID"
subfrmAbstractData.LinkMasterFields = "GranteeActivityID"
Else
subfrmAbstractData.SourceObject = "frmBlank"
End If
GLBL_SubFormName = strAbstractForm

subfrmAbstractData.Requery
Me.Refresh

End Sub
--------------------------

Maybe the call should be CALL me.subfrmAbstractData.form.LockEdit ????

Dirk Goldgar said:
LisaB said:
I am trying to get a call statement to work with a global name that
will be passed to the function. What is the correct syntax

This works if I use the actual form name
Call Me.[subtblGranteeContacts].Form.LockEdit

This does not work (trying to pass the form name through a global
variable) Call Me.[(GLBL_SubFormName)].Form.LockEdit

Call Me(GLBL_SubFormName).Form.LockEdit

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

(please reply to the newsgroup)
 
LisaB said:
also, the subform is not determined until the main form is loaded.
I use the following function

------------------------
Public Sub UpdateAppSource()
Dim strAbstractForm As String
Dim strStrategyArea As String
Dim strPhase As String

strStrategyArea = IIf(IsNull(Left(StrategyArea, 3)), "",
Left(StrategyArea, 3))
strAbstractForm = ""
strPhase = ""

If (strStrategyArea = "CBA") Or (strStrategyArea = "CBO") Or
(strStrategyArea = "CCD") Then
If (PhaseID = 1) Or ((PhaseID = 2) And (Left(MTCID, 5) =
"00100")) Then strPhase = "PI"
End If
strAbstractForm = "subfrm" & strStrategyArea & "AbstractData" &
strPhase subfrmAbstractData.SourceObject = strAbstractForm
subfrmAbstractData.LinkChildFields = "GranteeActivityID"
subfrmAbstractData.LinkMasterFields = "GranteeActivityID"
Else
subfrmAbstractData.SourceObject = "frmBlank"
End If
GLBL_SubFormName = strAbstractForm

subfrmAbstractData.Requery
Me.Refresh

End Sub

Yes. It's the name of the subform *control* on the main form that must
be specified, *not* the name of that control's SourceObject. If all
you're doing is swapping in different SourceObjects, then you can
hard-code the name of the subform control and not bother with the
variable.
 
Back
Top