USING VARIABLES AS FIELD NAMES

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. Im trying to use a variable as a field name. Here's an example:

myVar = "Forms!myForm!myField"

[myVar].value = "Whatever I want"

Does anyone know what I'm missing here?
 
Dan said:
Hello. Im trying to use a variable as a field name. Here's an
example:

myVar = "Forms!myForm!myField"

[myVar].value = "Whatever I want"

Does anyone know what I'm missing here?

I'm not sure if I've guessed right at what you want, but it might be:

Dim myVar As Access.Control

Set myVar - Forms!myForm!myField

myVar.Value = "Whatever I want"

Or it might be

Dim myVar As String

myVar = "myField"

Forms!myForm.Controls(myVar) = "Whatever I want"

Or it might be something else.
 
No, what I am looking for is the context in which you can use a variable tp
refer to a field. I think it's somehting like the following:

this![myVar].value = "Whatever I want"

I just can't get it right though
 
You mean
Me.Controls(myVar).Value

Or
Forms("FormName").Controls(myVar).Value


--

Ken Snell
<MS ACCESS MVP>

Dan said:
No, what I am looking for is the context in which you can use a variable
tp
refer to a field. I think it's somehting like the following:

this![myVar].value = "Whatever I want"

I just can't get it right though

Dan said:
Hello. Im trying to use a variable as a field name. Here's an example:

myVar = "Forms!myForm!myField"

[myVar].value = "Whatever I want"

Does anyone know what I'm missing here?
 
Great, so that seems to work for a form, but I'm haivng trouble referring to
a subform, which is what I really need. I've tried various combinations, but
cannot seem to get this to work.

Ken Snell said:
You mean
Me.Controls(myVar).Value

Or
Forms("FormName").Controls(myVar).Value


--

Ken Snell
<MS ACCESS MVP>

Dan said:
No, what I am looking for is the context in which you can use a variable
tp
refer to a field. I think it's somehting like the following:

this![myVar].value = "Whatever I want"

I just can't get it right though

Dan said:
Hello. Im trying to use a variable as a field name. Here's an example:

myVar = "Forms!myForm!myField"

[myVar].value = "Whatever I want"

Does anyone know what I'm missing here?
 
Dan said:
No, what I am looking for is the context in which you can use a
variable tp refer to a field. I think it's somehting like the
following:

I believe that's exactly what I posted two different ways to do.
 
Me.SubformName.Form.Controls(myVar).Value

where SubformName is the name of the subform control (the control that holds
the subform).

--

Ken Snell
<MS ACCESS MVP>

Dan said:
Great, so that seems to work for a form, but I'm haivng trouble referring
to
a subform, which is what I really need. I've tried various combinations,
but
cannot seem to get this to work.

Ken Snell said:
You mean
Me.Controls(myVar).Value

Or
Forms("FormName").Controls(myVar).Value


--

Ken Snell
<MS ACCESS MVP>

Dan said:
No, what I am looking for is the context in which you can use a
variable
tp
refer to a field. I think it's somehting like the following:

this![myVar].value = "Whatever I want"

I just can't get it right though

:

Hello. Im trying to use a variable as a field name. Here's an
example:

myVar = "Forms!myForm!myField"

[myVar].value = "Whatever I want"

Does anyone know what I'm missing here?
 
Back
Top