A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using variable for field name on form



 
 
Thread Tools Display Modes
  #1  
Old May 19th, 2004, 10:07 PM
J
external usenet poster
 
Posts: n/a
Default Using variable for field name on form

On a field I have two text boxes (ABC and DEF). These
text boxes get populated by the user with counts.
Values from frmMain (user enters)
ABC = 100
DEF = 200

Values in MyTable
MyField MyCount
ABC 0
DEF 0

I want to update the MyCount field in MyTable with the
values on the form based on the respective values in the
respective fields

MyArray = Array("ABC", "DEF")
for each item in MyArray
set rst = currentdb.openrecordset("Select * from MyTable
where MyField = '" & item & "'")
With rst
.Edit
!MyCount = forms!frmMain!ABC (or forms!frmMain!DEF
and so on as it goes through the array)
.Update
end with
next item

I've tried setting up a variable for forms!frmMainABC. I
used (var = "forms!frmMain!" & item) and tried declaring
the variable as different things (string, field etc), but
nothing seems to work. I know I can work around this, but
it seems to be more efficient (and require less code) if I
can just assign a variable to the fields on the form b/c
the field names match the id's in the table. Any
suggestions??

  #2  
Old May 19th, 2004, 10:53 PM
Marshall Barton
external usenet poster
 
Posts: n/a
Default Using variable for field name on form

J wrote:

On a field I have two text boxes (ABC and DEF). These
text boxes get populated by the user with counts.
Values from frmMain (user enters)
ABC = 100
DEF = 200

Values in MyTable
MyField MyCount
ABC 0
DEF 0

I want to update the MyCount field in MyTable with the
values on the form based on the respective values in the
respective fields

MyArray = Array("ABC", "DEF")
for each item in MyArray
set rst = currentdb.openrecordset("Select * from MyTable
where MyField = '" & item & "'")
With rst
.Edit
!MyCount = forms!frmMain!ABC (or forms!frmMain!DEF
and so on as it goes through the array)
.Update
end with
next item



!MyCount = forms!frmMain(item)

Be aware that "item" is a reserved word and may be confusing
to both you and to Access
--
Marsh
MVP [MS Access]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.