Form name recognition

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

The Select code below seems sort of silly to me in
that one would expect to be able to simply code
something like:

Forms![Me.OpenArgs]!cmboComposer = Me.CompLast & ", " & Me.CompFirst

I tried a few different syntax usages, but couldn't
get A2K-VBA to recognize the name of the form.
Am I stuck with the "silly Select", or did I just fail
to get the correct syntax using Me.OpenArgs?

Select Case Me.OpenArgs
Case "frmDataEntry"
Forms!frmDataEntry.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
Case "frmWorksDetails"
Forms!frmWorksDetails.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
End Select
 
Close: try this:

Forms(Me.OpenArgs)!cmboComposer = Me.CompLast & ", " & Me.CompFirst
 
Here's the correct syntax:

forms(me.openargs)!cmboComposer = Me.CompLast & ", " & Me.CompFirst
 
Thanks Ken, that worked nicely.

Would I be correct if I read that expression to
mean: In the "forms collection", use the name given
parenthetically to define the control that is to receive
the assigned string expression? (Seems logical, but
I don't know if it's technically accurate.)

Bill


Ken Snell (MVP) said:
Close: try this:

Forms(Me.OpenArgs)!cmboComposer = Me.CompLast & ", " & Me.CompFirst

--

Ken Snell
<MS ACCESS MVP>

Bill said:
The Select code below seems sort of silly to me in
that one would expect to be able to simply code
something like:

Forms![Me.OpenArgs]!cmboComposer = Me.CompLast & ", " & Me.CompFirst

I tried a few different syntax usages, but couldn't
get A2K-VBA to recognize the name of the form.
Am I stuck with the "silly Select", or did I just fail
to get the correct syntax using Me.OpenArgs?

Select Case Me.OpenArgs
Case "frmDataEntry"
Forms!frmDataEntry.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
Case "frmWorksDetails"
Forms!frmWorksDetails.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
End Select
 
Try

Dim strFormName as String

strFormName = Me!OpenArgs
If Len(strFormName) <> 0 Then
Forms.(strFormName)!cmboComposer
 
Thanks Sandra, see my post to Ken.
Bill


Sandra Daigle said:
Here's the correct syntax:

forms(me.openargs)!cmboComposer = Me.CompLast & ", " & Me.CompFirst


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

The Select code below seems sort of silly to me in
that one would expect to be able to simply code
something like:

Forms![Me.OpenArgs]!cmboComposer = Me.CompLast & ", " & Me.CompFirst

I tried a few different syntax usages, but couldn't
get A2K-VBA to recognize the name of the form.
Am I stuck with the "silly Select", or did I just fail
to get the correct syntax using Me.OpenArgs?

Select Case Me.OpenArgs
Case "frmDataEntry"
Forms!frmDataEntry.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
Case "frmWorksDetails"
Forms!frmWorksDetails.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
End Select
 
General syntax when you have the name of the form is this:

Forms("Name of the form").Controls("Name of the control")

or

Forms("Name of the form")![ControlName]

The argument for the Forms and Controls collections is a string in the above
examples. So you can use a variable in place of the string so long as the
variable contains a value that can be "read" as a string.


Alternatively, you can use a long integer that represents the index number
of the collection, but often that can be difficult to use because the index
number depends upon how many forms are already open and in which order they
were opened.

--

Ken Snell
<MS ACCESS MVP>


Bill said:
Thanks Ken, that worked nicely.

Would I be correct if I read that expression to
mean: In the "forms collection", use the name given
parenthetically to define the control that is to receive
the assigned string expression? (Seems logical, but
I don't know if it's technically accurate.)

Bill


Ken Snell (MVP) said:
Close: try this:

Forms(Me.OpenArgs)!cmboComposer = Me.CompLast & ", " & Me.CompFirst

--

Ken Snell
<MS ACCESS MVP>

Bill said:
The Select code below seems sort of silly to me in
that one would expect to be able to simply code
something like:

Forms![Me.OpenArgs]!cmboComposer = Me.CompLast & ", " & Me.CompFirst

I tried a few different syntax usages, but couldn't
get A2K-VBA to recognize the name of the form.
Am I stuck with the "silly Select", or did I just fail
to get the correct syntax using Me.OpenArgs?

Select Case Me.OpenArgs
Case "frmDataEntry"
Forms!frmDataEntry.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
Case "frmWorksDetails"
Forms!frmWorksDetails.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
End Select
 
Thanks Ken, you've cleared up for me questions
I've had for some time. I always had the sense that
collections were only accessible when the index
value was known. And, I knew that the index values
were more dynamic in the course of an applications
code path than I wanted to deal with in the general case.

I think our friend Albert in Canada touched on that
some time ago in one of his posts, but I never quite
assimilated the whole picture.

Thanks again,
Bill

Ken Snell (MVP) said:
General syntax when you have the name of the form is this:

Forms("Name of the form").Controls("Name of the control")

or

Forms("Name of the form")![ControlName]

The argument for the Forms and Controls collections is a string in the
above examples. So you can use a variable in place of the string so long
as the variable contains a value that can be "read" as a string.


Alternatively, you can use a long integer that represents the index number
of the collection, but often that can be difficult to use because the
index number depends upon how many forms are already open and in which
order they were opened.

--

Ken Snell
<MS ACCESS MVP>


Bill said:
Thanks Ken, that worked nicely.

Would I be correct if I read that expression to
mean: In the "forms collection", use the name given
parenthetically to define the control that is to receive
the assigned string expression? (Seems logical, but
I don't know if it's technically accurate.)

Bill


Ken Snell (MVP) said:
Close: try this:

Forms(Me.OpenArgs)!cmboComposer = Me.CompLast & ", " & Me.CompFirst

--

Ken Snell
<MS ACCESS MVP>

The Select code below seems sort of silly to me in
that one would expect to be able to simply code
something like:

Forms![Me.OpenArgs]!cmboComposer = Me.CompLast & ", " & Me.CompFirst

I tried a few different syntax usages, but couldn't
get A2K-VBA to recognize the name of the form.
Am I stuck with the "silly Select", or did I just fail
to get the correct syntax using Me.OpenArgs?

Select Case Me.OpenArgs
Case "frmDataEntry"
Forms!frmDataEntry.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
Case "frmWorksDetails"
Forms!frmWorksDetails.Form!cmboComposer = Me.CompLast & ", " &
Me.CompFirst
End Select
 
Back
Top