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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|