Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to assign values to field in form dynamically

Status
Not open for further replies.

Scoty

Programmer
Oct 25, 2000
278
US
Hey Guys,
I have a database which reads data from another program. I want to assign data I receive to form fields. My form fields are named as
Code:
FirstName1, FirstName2, FirstName3...
ect.,ect. now in my database I have these setup in a loop such as:
Code:
y = 1
Do Until FirstName = "          "
FirstName = "FirstName" & y
FirstName = GetText(1 , 3, 10)
y = y + 1
Loop
now what happens is, of couse, A97 reassigns the value of
Code:
FirstName
to the value of
Code:
GetText(1, 3, 10)
instead of assigning the value of
Code:
GetText(1, 3, 10)
to the field (on the form) that
Code:
FirstName
is assigned to first.
Help Please
scoty::)
 
Try this:
Code:
    Me.Controls(FirstName) = GetText(1, 3, 10)

In your statement, you're not "assigning" FirstName to a form field, you're just giving it a string value that happens to be the name of a form field. Then you're trying to use FirstName as if it was a control. What you really need is a reference to the control whose name is in FirstName. That's what Me.Controls(FirstName) does.
 
Thanks Rick
What I ended up doing was
Code:
Dim FirstName as Control
and then
Code:
Set FirstName = "Me.FisrtName" & y
in my loop. This Set FirstName as the control FirstName1, FirstName2...so on and so on. I did have the coding correct it was field names that were throwing me off. I had FirstName1, FirstName2, FName3...So the program got to the third entry and choked. Got it worked out now and it is wonderful.

Thanks for you help though
Scott ::)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top