accessing control name stored in a variable 
Author Message
 accessing control name stored in a variable

Here is a simplified version of what I a trying to accomplish (for now,
better not to ask why!).

A variable strFieldName has the following value:
"Form!FrmWhatever.FieldWhatever".

I now want to assign a value to the particular control identified in
strFieldName. In other languages, I would use indirect referencing to
say "store the value abc not in the variable strFieldName, but in the
variable strFieldName is pointing to".

Does anyone know if Access supports this kind of thing?

Chuck



Sat, 19 Oct 2002 03:00:00 GMT  
 accessing control name stored in a variable
Chuck,

AFIK, Access doesn't permit this.

If you want to split the string into two pieces, either keeping
it separate or using InStr and Mid to separate it, then you can
use this syntax to accomplish the assignment.

    Forms(strFormName)(strControlName) = somevalue

HTH,
Marsh



Quote:
>Here is a simplified version of what I a trying to accomplish
(for now,
>better not to ask why!).

>A variable strFieldName has the following value:
>"Form!FrmWhatever.FieldWhatever".

>I now want to assign a value to the particular control
identified in
>strFieldName. In other languages, I would use indirect
referencing to
>say "store the value abc not in the variable strFieldName, but
in the
>variable strFieldName is pointing to".

>Does anyone know if Access supports this kind of thing?

>Chuck

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


Sat, 19 Oct 2002 03:00:00 GMT  
 accessing control name stored in a variable
Thanks Marshall. I guess I'm still locked in a procedural programming
mentality.

Chuck

Quote:

> Chuck,

> AFIK, Access doesn't permit this.

> If you want to split the string into two pieces, either keeping
> it separate or using InStr and Mid to separate it, then you can
> use this syntax to accomplish the assignment.

>     Forms(strFormName)(strControlName) = somevalue

> HTH,
> Marsh



> >Here is a simplified version of what I a trying to accomplish
> (for now,
> >better not to ask why!).

> >A variable strFieldName has the following value:
> >"Form!FrmWhatever.FieldWhatever".

> >I now want to assign a value to the particular control
> identified in
> >strFieldName. In other languages, I would use indirect
> referencing to
> >say "store the value abc not in the variable strFieldName, but
> in the
> >variable strFieldName is pointing to".

> >Does anyone know if Access supports this kind of thing?

> >Chuck

> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Sat, 19 Oct 2002 03:00:00 GMT  
 accessing control name stored in a variable
As Marshall said, Access doesn't permit this type of thing.

That is it doesn't let you SET what's on the left of an "=", but you CAN
read what's in non-VB objects using the Eval function.

Using your example, the following would set sTestVar2 to "TestValue":

Forms!FrmWhatever!FieldWhatever="TestValue"
sTestVar1="Forms!FrmWhatever!FieldWhatever"
sTestVar2=Eval(sTestVar1)

The following is one of my responses to someone else with Eval problem.
I've re-posted it here.
Hope it gives you some new insight.

-----------

The main thing to know when you use the Eval statement in code is... only
things that are available in SQL, are available to Eval.  Yuck!  That means
variable names cannot be Evaled.  Form/Report/Control names can be.

The only way around in this is to build the string so that the variables are
replaced with quoted strings for the Eval statement.

Functions calls however, CAN be Evaled, so a function call inside the Eval
can get variables available to it, and return them.
Example: Eval("Chr$(65)") returns "A".

Change the appropriate lines in your code to these:

    vbStringPassed = strFieldName1 & " along with " & strFieldName2
    strAnswer = "'" & vbStringPassed & "'"
    Debug.Print "Please provide " & Eval(strAnswer) & " when you submit your
request."

or

    vbStringPassed = "'" & strFieldName1 & " along with " & strFieldName2 &
"'"
    Debug.Print "Please provide " & Eval(vbStringPassed ) & " when you
submit your request."

or

    vbStringPassed = strFieldName1 & " along with " & strFieldName2
    Debug.Print Eval("'Please provide " & vbStringPassed & " when you submit
your request.'")

--
go play,
Barry
Please respond to newsgroups, so other readers
can benefit from the conversation.
----------

(Thread contrinues below)

Quote:

>I need help in assembling a string within a string,
> in the following manner. The input to a procedure
> is data that consists of a valid VB string statement
> such as -- "strFieldName1 & 'along with'  & strFieldName2".

> For this example let just say that these fields are defaulted to
> strFieldName1="size" and strFieldName2="Quantity".
> This string can vary in contents and number of fields and is
> generated by another procedure, which I have.

> The procedure I need would insert it into another string :
> such as Str1='Please provide ' & strFieldName1 &
> VBstringPassed & 'when you submit your request.'

> which would translate in this example to something like:
> Str1='Please provide ' & strFieldName1 & ' along with '
> & _ strFieldName1  & 'when you submit your request.'

> The result string would be:
> Please provide size along with Quantity when you submit
> your request.

> The problem is that given the VB string statement such as
> strA & strB in the form of data how do I tell Access to
> execute it as the right side of an expression and return
> the results.

> StrResults= strA & strB

> What I get is strA & strB not the values in strA and strB.
> Even if I try to get the value of the passed string prior to
> insertion I need some way to force Access to evaluate
> and return the values.

> Any suggestions would be appreciated.

>TomB

---------------

(Thread contrinues here)



- Show quoted text -

Quote:
> Here is a simplified version of what I a trying to accomplish (for now,
> better not to ask why!).

> A variable strFieldName has the following value:
> "Form!FrmWhatever.FieldWhatever".

> I now want to assign a value to the particular control identified in
> strFieldName. In other languages, I would use indirect referencing to
> say "store the value abc not in the variable strFieldName, but in the
> variable strFieldName is pointing to".

> Does anyone know if Access supports this kind of thing?

> Chuck



Wed, 23 Oct 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Setting a control who's name is stored in a variable

2. Reffering to Control when Name is stored in Variable

3. Referencing a variable name stored in a variable

4. Variables stored in Range Names

5. Store the active worksheet(name) into variable

6. Storing subform name in variable when clicked

7. Temp QueryDef or Stored QueryDef Variable Name

8. Call Function using Func Name stored in variable

9. Help with storing variable name in a table

10. show userform when name is stored in variable


 
Powered by phpBB® Forum Software © phpBB Group