J
Jim
I have a form that reads a table and using some of that data, writes to
another table. Works fine.
Table Y has field names are x_1, x_2 through x_10. The following snips
of code work fine.
sqlCode = "SELECT Y.x_1, Y.x_2, Y.x_3, etc...;"
set dynSet = dbs.OpenRecordset(sqlCode, dbOpenDynaset)
set dynOut = dbs("outPutTable", dbOpenDynaset)
With dynSet
.moveFirst
while not .OEF
.AddNew
dynOut!r = !x_1
.Update
.AddNew
dynOut!r = !x_2
.Update
etc...
============================
What I want is:
With dynSet
.moveFirst
while not .OEF
for x = 1 to 10
temp_field_name = "!x_" & trim(x)
.AddNew
dynOut!r = temp_field_name
.Update
next x
.moveNext
loop
End With
<<<<<<<<<<<<<>>>>>>>>>>>>
The problem I'm having is that as coded above Access thinks
temp_field_name is a literal. If I take out the "!" and code
dynOut!r = !temp_field_name then it can't find the item in the collection.
Is there any way around this? I know I can change the query to use the
variable as the field name but that doesn't sound like a workable
solution either.
TIA
Jim
P.S. since I have code that works, this is really an academic exercise...
another table. Works fine.
Table Y has field names are x_1, x_2 through x_10. The following snips
of code work fine.
sqlCode = "SELECT Y.x_1, Y.x_2, Y.x_3, etc...;"
set dynSet = dbs.OpenRecordset(sqlCode, dbOpenDynaset)
set dynOut = dbs("outPutTable", dbOpenDynaset)
With dynSet
.moveFirst
while not .OEF
.AddNew
dynOut!r = !x_1
.Update
.AddNew
dynOut!r = !x_2
.Update
etc...
============================
What I want is:
With dynSet
.moveFirst
while not .OEF
for x = 1 to 10
temp_field_name = "!x_" & trim(x)
.AddNew
dynOut!r = temp_field_name
.Update
next x
.moveNext
loop
End With
<<<<<<<<<<<<<>>>>>>>>>>>>
The problem I'm having is that as coded above Access thinks
temp_field_name is a literal. If I take out the "!" and code
dynOut!r = !temp_field_name then it can't find the item in the collection.
Is there any way around this? I know I can change the query to use the
variable as the field name but that doesn't sound like a workable
solution either.
TIA
Jim
P.S. since I have code that works, this is really an academic exercise...