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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Referencing Form Fields Dynamicly



 
 
Thread Tools Display Modes
  #1  
Old July 10th, 2006, 03:50 PM posted to microsoft.public.access.forms
rburna
external usenet poster
 
Posts: 5
Default 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  
Old July 10th, 2006, 04:14 PM posted to microsoft.public.access.forms
RoyVidar
external usenet poster
 
Posts: 417
Default 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  
Old July 10th, 2006, 04:14 PM posted to microsoft.public.access.forms
Wayne Morgan
external usenet poster
 
Posts: 73
Default 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  
Old July 10th, 2006, 04:39 PM posted to microsoft.public.access.forms
rburna
external usenet poster
 
Posts: 5
Default 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

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 12:26 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.