Concatenate Me. with a Variable

  • Thread starter Thread starter Mercadogs
  • Start date Start date
M

Mercadogs

Greetings!

Is it possible to concatenate the "Me" keyword with a variable declared in
a VBA code? I need to know because I would like to make a function that would
could use the names of different controls as parameters.

Everything I've tried doesn't work and I can't find an answer Online.

See an example below of one of the attempts I've tried:
NOTE: I am simply interested in find out if such a concatenation is
possible, not an evaluation of the code... Thanks! -Gabriel
......................................................................................
Private Sub Search_Click()
Dim crit_1 As String
Dim crit_2 As String

crit_1 = Me.&Crit_2 ' Where Crit_2 would be the name of a control

End Sub
............................................................................................
 
Me.Controls("StringNameofControl")



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
Thanks a million, John! This worked like a charm... I was able to use
Me.Controls(VariableWithTheNameOfaConrolAssignedToIt). If more of your
expertise is readily available, can I ask another question?

How can I do something similar to above with the syntax
Forms!FormName!NameofControl? So, instead of the NameofControl, can I have
syntax:
Forms![FormName]![NameofVariableWithTheNameofAControlAssignedToIt] ?

So for example :
Variable = Screen.PreviousControl.Name
(Then)
Forms![FormName]!&[Variable] ' or something like this ?

....Obviously this exact format above didn't work, but do you have any
suggestions?

Thanks again, John!
 
You need

Forms![FormName].Controls("NameofAControl")

And, just in case it's useful to you, that can also be extended to

Forms("NameOfAForm").Controls("NameofAControl")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Mercadogs said:
Thanks a million, John! This worked like a charm... I was able to use
Me.Controls(VariableWithTheNameOfaConrolAssignedToIt). If more of your
expertise is readily available, can I ask another question?

How can I do something similar to above with the syntax
Forms!FormName!NameofControl? So, instead of the NameofControl, can I have
syntax:
Forms![FormName]![NameofVariableWithTheNameofAControlAssignedToIt] ?

So for example :
Variable = Screen.PreviousControl.Name
(Then)
Forms![FormName]!&[Variable] ' or something like this ?

...Obviously this exact format above didn't work, but do you have any
suggestions?

Thanks again, John!


John Spencer said:
Me.Controls("StringNameofControl")



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
Hi Douglas:

Thanks a lot for sharing that knowledge!

I'm sure that it is trustworthy, but how do I get it to work in an SQL
assigned as the Rowsource of a listbox ? I tried several things that didn't
work.

I have:
............................................
StingSQL = " [..code ommitted...] WHERE
WRITNumber=Forms![FormName].Controls( VariableThatIsAssignedAControlName ) ; "

Me.[ListBoxName].RowSource = StringSQL
........................................................

I aslo tried Forms(VariableThatisAsssignedAFormName).Controls(
VariableThatIsAssignedAControlName )

and

Forms![FormName].Controls( & VariableThatIsAssignedAControlName & )

but, to no avails! I get no error but I also get no info in the listbox. Can
you help with this?

Thanks, Gabriel...






Douglas J. Steele said:
You need

Forms![FormName].Controls("NameofAControl")

And, just in case it's useful to you, that can also be extended to

Forms("NameOfAForm").Controls("NameofAControl")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Mercadogs said:
Thanks a million, John! This worked like a charm... I was able to use
Me.Controls(VariableWithTheNameOfaConrolAssignedToIt). If more of your
expertise is readily available, can I ask another question?

How can I do something similar to above with the syntax
Forms!FormName!NameofControl? So, instead of the NameofControl, can I have
syntax:
Forms![FormName]![NameofVariableWithTheNameofAControlAssignedToIt] ?

So for example :
Variable = Screen.PreviousControl.Name
(Then)
Forms![FormName]!&[Variable] ' or something like this ?

...Obviously this exact format above didn't work, but do you have any
suggestions?

Thanks again, John!


John Spencer said:
Me.Controls("StringNameofControl")



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Mercadogs wrote:
Greetings!

Is it possible to concatenate the "Me" keyword with a variable
declared in
a VBA code? I need to know because I would like to make a function that
would
could use the names of different controls as parameters.

Everything I've tried doesn't work and I can't find an answer Online.

See an example below of one of the attempts I've tried:
NOTE: I am simply interested in find out if such a concatenation is
possible, not an evaluation of the code... Thanks! -Gabriel
....................................................................................
Private Sub Search_Click()
Dim crit_1 As String
Dim crit_2 As String

crit_1 = Me.&Crit_2 ' Where Crit_2 would be the name of a control

End Sub
..........................................................................................
 
Correction:
I tried :
Forms(""FormName"").Controls(
VariableThatIsAssignedAControlName )
Not:
Forms(VariableThatisAsssignedAFormName).Controls(
VariableThatIsAssignedAControlName )





Douglas J. Steele said:
You need

Forms![FormName].Controls("NameofAControl")

And, just in case it's useful to you, that can also be extended to

Forms("NameOfAForm").Controls("NameofAControl")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Mercadogs said:
Thanks a million, John! This worked like a charm... I was able to use
Me.Controls(VariableWithTheNameOfaConrolAssignedToIt). If more of your
expertise is readily available, can I ask another question?

How can I do something similar to above with the syntax
Forms!FormName!NameofControl? So, instead of the NameofControl, can I have
syntax:
Forms![FormName]![NameofVariableWithTheNameofAControlAssignedToIt] ?

So for example :
Variable = Screen.PreviousControl.Name
(Then)
Forms![FormName]!&[Variable] ' or something like this ?

...Obviously this exact format above didn't work, but do you have any
suggestions?

Thanks again, John!


John Spencer said:
Me.Controls("StringNameofControl")



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Mercadogs wrote:
Greetings!

Is it possible to concatenate the "Me" keyword with a variable
declared in
a VBA code? I need to know because I would like to make a function that
would
could use the names of different controls as parameters.

Everything I've tried doesn't work and I can't find an answer Online.

See an example below of one of the attempts I've tried:
NOTE: I am simply interested in find out if such a concatenation is
possible, not an evaluation of the code... Thanks! -Gabriel
....................................................................................
Private Sub Search_Click()
Dim crit_1 As String
Dim crit_2 As String

crit_1 = Me.&Crit_2 ' Where Crit_2 would be the name of a control

End Sub
..........................................................................................
 
You need to concatenate in the Value in the control, not a reference to the
control.

StingSQL = " [..code ommitted...] WHERE
WRITNumber=" & Forms![FormName].Controls( VariableThatIsAssignedAControlName
& ") ; "

John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
Hi Douglas:

Thanks a lot for sharing that knowledge!

I'm sure that it is trustworthy, but how do I get it to work in an SQL
assigned as the Rowsource of a listbox ? I tried several things that didn't
work.

I have:
...........................................
StingSQL = " [..code ommitted...] WHERE
WRITNumber=Forms![FormName].Controls( VariableThatIsAssignedAControlName ) ; "

Me.[ListBoxName].RowSource = StringSQL
.......................................................

I aslo tried Forms(VariableThatisAsssignedAFormName).Controls(
VariableThatIsAssignedAControlName )

and

Forms![FormName].Controls( & VariableThatIsAssignedAControlName & )

but, to no avails! I get no error but I also get no info in the listbox. Can
you help with this?

Thanks, Gabriel...






Douglas J. Steele said:
You need

Forms![FormName].Controls("NameofAControl")

And, just in case it's useful to you, that can also be extended to

Forms("NameOfAForm").Controls("NameofAControl")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Mercadogs said:
Thanks a million, John! This worked like a charm... I was able to use
Me.Controls(VariableWithTheNameOfaConrolAssignedToIt). If more of your
expertise is readily available, can I ask another question?

How can I do something similar to above with the syntax
Forms!FormName!NameofControl? So, instead of the NameofControl, can I have
syntax:
Forms![FormName]![NameofVariableWithTheNameofAControlAssignedToIt] ?

So for example :
Variable = Screen.PreviousControl.Name
(Then)
Forms![FormName]!&[Variable] ' or something like this ?

...Obviously this exact format above didn't work, but do you have any
suggestions?

Thanks again, John!


:


Me.Controls("StringNameofControl")



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Mercadogs wrote:
Greetings!

Is it possible to concatenate the "Me" keyword with a variable
declared in
a VBA code? I need to know because I would like to make a function that
would
could use the names of different controls as parameters.

Everything I've tried doesn't work and I can't find an answer Online.

See an example below of one of the attempts I've tried:
NOTE: I am simply interested in find out if such a concatenation is
possible, not an evaluation of the code... Thanks! -Gabriel
....................................................................................
Private Sub Search_Click()
Dim crit_1 As String
Dim crit_2 As String

crit_1 = Me.&Crit_2 ' Where Crit_2 would be the name of a control

End Sub
..........................................................................................
 
Back
Top