Re: Public variable named from field content
- From: rwfreeman <rfreeman37@xxxxxxxxxxx>
- Date: Wed, 16 Apr 2008 12:33:11 -0700 (PDT)
On Apr 16, 1:29 pm, Dale Fye <dale....@xxxxxxxxxx> wrote:
I'm not aware of anyway to do what you are trying to accomplish. You could
store the variable name and value in a collection, or you could store these
values in a control on a form. I occassionally store public variables in
text boxes on my form. I extend the length or width of a form, and put
textboxes (set the TabStop to False, and scrollbars set to none) in that
extended area. With the TabStop set to False and the scrollbars turned off,
the user should never get to see these textboxes, but they provide you a way
to see what is in them as you are developing.
Then you could name them txt_GCF1, txt_gAFa, ...
and could reference them as follows:
Dim rs as DAO.Recordset
Set rs = currentd.openrecordset("Select * FROM yourTable")
While not rs.eof
me.Controls("txt_" & rs(2)).Value = rs(3)
rs.movenext
Wend
rs.close
set rs = nothing
HTH
Dale
--
Don''t forget to rate the post if it was helpful!
email address is invalid
Please reply to newsgroup only.
"rwfreeman" wrote:
I've declared 20 Public variables in the Declaration section of a
General module:
Public gCF1 as Double, gAFa as Double, etc.
These variables will contain values that are used in subsequent
calculations in the project and they represent default conditions.
However the user could elect to override one or all of them
temporarally and perform a non-default calculation. So my thought is
to assign values from the default table to public variables that could
be altered if the user chooses to do so.
Values for the variables are stored in a table that is queried to
create a recordset ("rst") that has a structure like so
rst.Fields(2) rst.Fields(3)
CF1 0.000001
AFa 0.2
so that the name of the variable is in .Fields(2) and its numeric
value is in .Fields(3). Thus, gCF1 should have a value of 0.000001
and gAFa should have a value of 0.2.
Looping through the recordset and using a SELECT CASE
rst.Fields(2).Value statement works but seems to me to be rather
inelegant and inflexible. If, instead of the SELECT CASE, I use a
statement such as
"g" & rst.Fields(2).Value = rst.Fields(3).Value
an compile error results ("Expected identifier or line number.")
FoxBase had a "macro substitution" (&VariableName=VariableValue) which
worked perfectly for this. What's the VBA equivalent?
Thanks for the help- Hide quoted text -
- Show quoted text -
Dale, thanks. I believe I'll stick with my SELECT CASE ... END CASE
construct.
Richard
.
- Follow-Ups:
- Re: Public variable named from field content
- From: Dale Fye
- Re: Public variable named from field content
- References:
- Public variable named from field content
- From: rwfreeman
- RE: Public variable named from field content
- From: Dale Fye
- Public variable named from field content
- Prev by Date: RE: Save record & stay on same record
- Next by Date: Record Selecting
- Previous by thread: RE: Public variable named from field content
- Next by thread: Re: Public variable named from field content
- Index(es):
Relevant Pages
|