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
|
|||
|
|||
Referencing Form Fields Dynamicly
Ok, I can't seem to find any information on accessing a field name
dynamicly.... Here is the code dim iCount dim iTotal iTotal = 0 do while iCount = 16 tThisField = "txtOct" & iCount ' This specifies the field I should be checking iTotal = iTotal + VAL(Eval(tThisField)) loop Logicly this should work, but I keep running into an error telling me that it can't find the field txtOct1 which is a valid field on the form.... What am I doing wrong? Richard |
#2
|
|||
|
|||
Referencing Form Fields Dynamicly
Ok, I can't seem to find any information on accessing a field name
dynamicly.... Here is the code dim iCount dim iTotal iTotal = 0 do while iCount = 16 tThisField = "txtOct" & iCount ' This specifies the field I should be checking iTotal = iTotal + VAL(Eval(tThisField)) loop Logicly this should work, but I keep running into an error telling me that it can't find the field txtOct1 which is a valid field on the form.... What am I doing wrong? Richard Try something like this iTotal = iTotal + me.controls("txtOct" & cstr(iCount)).value -- Roy-Vidar |
#3
|
|||
|
|||
Referencing Form Fields Dynamicly
A few problems:
1) "Dim iCount" and "Dim iTotal" will give you a Variant, not an Integer. If you want an Integer, then it should be "Dim iCount As Integer" and "Dim iTotal As Integer". 2) There is nothing in our Do While loop to increment iCount, so it will always be =16 (i.e. infinite loop). I believe you may want a For...Next loop instead. (For iCount = 1 To 16) 3) I assume that tThisField is supposed to be a text variable, but it hasn't been defined (Dim tThisField As String). 4) The syntax to refer to a field by concatenating the name as you are is tThisField = Me.Controls("txtOct" & iCount) or tThisField = Me.Recordset.Fields("txtOct" & iCount) I would prefer the first one. I've never used the second one, but I believe it would work. In the first one you are actually referring to the name of the control bound to the desired field, not to the field itself. -- Wayne Morgan MS Access MVP "rburna" wrote in message ups.com... Ok, I can't seem to find any information on accessing a field name dynamicly.... Here is the code dim iCount dim iTotal iTotal = 0 do while iCount = 16 tThisField = "txtOct" & iCount ' This specifies the field I should be checking iTotal = iTotal + VAL(Eval(tThisField)) loop Logicly this should work, but I keep running into an error telling me that it can't find the field txtOct1 which is a valid field on the form.... What am I doing wrong? Richard |
#4
|
|||
|
|||
Referencing Form Fields Dynamicly
Wayne,
Thanks for the input using tThisField = Me.Controls("txtOct" & iCount) was able to give me the reference to the value I was looking for Thanks..... Richard |
Thread Tools | |
Display Modes | |
|
|