Michael,
Unfortunately this would not be possible. The reason why
I need to select the field name, is that this table has
200 fields and 6237 'rows' of data.
The calcuation I am trying to undertake is: all the
values in the table of the select field multiplied by a
value in a related table and then grouped based on values
from a third table (related). In as standard it would be
as follows:
SELECT [Food Consumption].Country_Name, Sum([FAOstat]!
[Prot_g/100g]*[Food Consumption]![GMPerPPerDayRefuse]
*0.01) AS ProJSupply
FROM (FAOstat INNER JOIN [Food Consumption] ON
FAOstat.Food_code = [Food Consumption].Food_code) INNER
JOIN [Country Total] ON ([Food Consumption].Food_code =
[Country Total].Food_Code) AND ([Food
Consumption].Country_Name = [Country Total].Country)
GROUP BY [Food Consumption].Country_Name;
Ideally, I want to select the field name with a combobox.
So insted of ([FAOstat]![Prot_g/100g]. I want to select a
any one of the fields in the FAOstat table. I have
created a combobox and bounded the combobox to the fields
of the table. The select field in the combobox is then
assigned to a module variable of "X".
Now, I want to preform the calcualtion using the selected
field. (eg)
SELECT [Food Consumption].Country_Name, Sum([FAOstat]!
[SELECTED COMBOBOX VALUE]*[Food Consumption]!
[GMPerPPerDayRefuse]*0.01)...
Is this possible?
cheers
Mark
-----Original Message-----
Hi,
Use switch rather than choose, but again, a proper table design would
more elegantly solve that problem. It seems you need the NAME of the field
as data, but the field name is NOT data accessible by the database. So,
instead of
ClientID, Jan, Feb, Mar, Apr ' Fields name
1010, 1, 2, 3, 4 ' data
have
ClientID, TheName, TheValue 'Fields name
1010 Jan 1
1010 Feb 2
1010 Mar 3
1010 Apr 4
and it is then just a matter of a very general simple criteria:
SELECT TheValue FROM myTable WHERE TheName='Apr'
because the data is now just that, data.
Hoping it may help,
Vanderghast, Access MVP
Mark said:
Ok, this is turing out to be quite difficult. What about
a mixture of VBA?
If I declare X as a string and X is assigned the name of
the field, after the user selects the value in the
combobox. Is it possible to structure a query so that the
string becomes the name of the field?
(following from the other example)
query: sum(10*[tableA]!X)
with X being string that has been assigned the name of
the field?
Cheers and thanks in advance
Mark
-----Original Message-----
Hi,
In general, it is not suggested (and not directly
supported) to have a
"variable" field name. You can try something like:
SELECT CHOOSE(myIndex, field1, field2, field3,
field4, field5)
FROM myTable
and it would return field1, ... field5 dependant on the
value of myIndex.
I would not dream to use that myself... unless I would
be designing a tool
for databases. In general, I would change the table
design to use more
standard SQL statements.
Hoping it may help,
Vanderghast, Access MVP
I have a table with (eg) 8 fields and about 200
numberical records in each field. I want to be able to
have the field names in a combobox so that I can
select a
particular field and then output a table query with all
the values in the field multiplied by another value.
for example:
Field Names in [TableA]: FA, FB, FC, FD
First, how do I get Access to list the filed names in
the
table?
Second, using the combobox, I select field [FA]. so How
would I structure the query so that I could calculate
temp:sum(10*[TableA]![combobox selected field])
or
temp:sum(10*[TableA]![FA])
Help and thanks in advance
Mark
.