Dynamically Access Field Names from Recordset

G

Guest

Hello,

I am populating a form and wondered how to populate the fields on the form
through dynamically accessing the fields in the dataset.

In this case, I have field1, field2, field3 on the form, which correspond to
fields in the recordset I am querying.

While I can dynamically access the fields on the form, how do I do the same
to get the field in the recordset.

See the code below:

i = 1
Do Until i = 11
Labeltext = "cboCustomField" & Trim(Str(i)) & "Name_Label" ' field
on the form)
Labeltext2 = "CriteriaDesc" & Trim(Str(i)) ' field in the file

Me(Labeltext).Caption = rst![Labeltext2] 'GET ERROR HERE, DOES NOT
RECOGNIZE CriteriaDesc1, CriteriaDesc2... at a valid field name in the
recordset

I've tried rst!(Labeltext2).Value and rst!(Labeltext2).UnderlyingValue.

Any ideas?

Thanks,

--David
 
R

RoyVidar

David wrote in message
Hello,

I am populating a form and wondered how to populate the fields on the form
through dynamically accessing the fields in the dataset.

In this case, I have field1, field2, field3 on the form, which correspond to
fields in the recordset I am querying.

While I can dynamically access the fields on the form, how do I do the same
to get the field in the recordset.

See the code below:

i = 1
Do Until i = 11
Labeltext = "cboCustomField" & Trim(Str(i)) & "Name_Label" ' field
on the form)
Labeltext2 = "CriteriaDesc" & Trim(Str(i)) ' field in the file

Me(Labeltext).Caption = rst![Labeltext2] 'GET ERROR HERE, DOES NOT
RECOGNIZE CriteriaDesc1, CriteriaDesc2... at a valid field name in the
recordset

I've tried rst!(Labeltext2).Value and rst!(Labeltext2).UnderlyingValue.

Any ideas?

Thanks,

--David

That's very close ... just drop the bang ...

rst(Labeltext2).value

though my preferences would be something like this

rst.fields(Labeltext2).value
 
G

Guest

Voila. Thanks Roy.
--
David


RoyVidar said:
David wrote in message
Hello,

I am populating a form and wondered how to populate the fields on the form
through dynamically accessing the fields in the dataset.

In this case, I have field1, field2, field3 on the form, which correspond to
fields in the recordset I am querying.

While I can dynamically access the fields on the form, how do I do the same
to get the field in the recordset.

See the code below:

i = 1
Do Until i = 11
Labeltext = "cboCustomField" & Trim(Str(i)) & "Name_Label" ' field
on the form)
Labeltext2 = "CriteriaDesc" & Trim(Str(i)) ' field in the file

Me(Labeltext).Caption = rst![Labeltext2] 'GET ERROR HERE, DOES NOT
RECOGNIZE CriteriaDesc1, CriteriaDesc2... at a valid field name in the
recordset

I've tried rst!(Labeltext2).Value and rst!(Labeltext2).UnderlyingValue.

Any ideas?

Thanks,

--David

That's very close ... just drop the bang ...

rst(Labeltext2).value

though my preferences would be something like this

rst.fields(Labeltext2).value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top