Referring to a recordset field name

F

franky

I have a recordset and I'm attempting access the fields using a variable
name. The following doesn't work:

myItem = rs!Left(listItem, InStr(1, listItem, "(") - 1)

How would I accoumplish this? Not sure is this matters, but the recordset
is declared as: Dim rs As rdoResultset

Thanks in advance!
 
R

Ron Weiner

Try

myItem = Left(rs!listItem, InStr(1, rs!listItem, "(") - 1)

Assuming that the name of the column is "listItem" and you want to get all
of the chars to the left of the first opening parenthesis found in the
column.

You need to get some error checking going here as you will get an error
whenever there is no opening parenthesis in listItem.
 
F

franky

Hmmm... still having the problem. I'm trying to use a variable name instead
of the field name. The "variablename" contains the fieldname:

I've haven't had any luck trying things like:

rs(variablename)
rs(" & variablename & ")
rs!variablename

any other sugestions?
 
R

Ron Weiner

If

myItem = Left(rs(variablename), InStr(1, rs(variablename), "(") - 1)

dosent work then post all of your code in the Function / Sub so we can try
to figure out what is going on.
 
C

Cydney

Would this same type of solution work to use a field name on a report? For
example: I have 4 quarters on my report that I want to populate with a value.
I don't know which field to put the number in until I know which quarter
we're starting in (information which the user passes to the form). Once I
know the quarter I need to add that number (i.e. 1,2,3,or 4) to the actual
field name (i.e. me.qtr & 1 .value = 500 or me.qtr &2 .value = 500, ...etc.).
Is there a good way to do that?
 
K

Ken Snell [MVP]

Do you mean field or control on the report? Most likely control.

This works for what you seek to do:

Me.Controls("NameOfControl" & "1").Value = "YourValue"
 
C

Cydney

Yes, I meant control on a form.
And that's perfect. Thanks for the help!
--
THX cs


Ken Snell said:
Do you mean field or control on the report? Most likely control.

This works for what you seek to do:

Me.Controls("NameOfControl" & "1").Value = "YourValue"
 

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