Variables for Field Names?

  • Thread starter Thread starter MAB
  • Start date Start date
M

MAB

Is it possible to edit a field in a table by using a variable to represent
the name of the field? For example, I ave a table with the following field
names A0900, A0930, A1000, A1030, etc...

I have a variable called VStartTime that contains the name of one of the
fields. In one instance VStartTime might be A0930 and another time
VStartTime might be A1030, etc. It depends on alot of other tings in the
code. But when I want to update a field value (as below), can I substitute
VStartTime for the actual field name. As written below, I get the 'Item not
found in this collection" error. But is there a way to make it see
!VStartTime as !A0930 where VStartTime = "A0930"

....
If Not .NoMatch Then
.Edit
!VStartTime = 1
.Update
End If
....

Thanks!
 
MAB said:
Is it possible to edit a field in a table by using a variable to represent
the name of the field? For example, I ave a table with the following field
names A0900, A0930, A1000, A1030, etc...

I have a variable called VStartTime that contains the name of one of the
fields. In one instance VStartTime might be A0930 and another time
VStartTime might be A1030, etc. It depends on alot of other tings in the
code. But when I want to update a field value (as below), can I substitute
VStartTime for the actual field name. As written below, I get the 'Item not
found in this collection" error. But is there a way to make it see
!VStartTime as !A0930 where VStartTime = "A0930"

...
If Not .NoMatch Then
.Edit
!VStartTime = 1
.Update
End If


You can that with this syntax:

.Fields(VStartTime) = 1

Now that I've answered the question, you have to get the
standard lecture about proper normalization of your
tables/fields, but I'll keep it short - this time ;-)).

Instead of having a lot of fields that contain a "time"
value in their name, you should have another table with a
separate **row** for each time value.
 
Back
Top