Loop through fields to get value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table with 8 numeric (integer) fields plus one ID field. I’m trying
to set the value of 8 option groups to what is in the associated field using
the code below, but I get the following message:

Error No: 2465; Description: Microsoft Access can’t find the field “
referred to in your expression.

1. What am I doing wrong?
2. Is there a better way of looping through each field and passing its value
to the associate option group?

Dim i As Integer
Dim j As String
Dim aryArea As Variant
Dim fld1 As Fields

aryArea = Array("RM", "CO", "AR", "MA", "MO", "PU", "PS", "CC")
Me(j).Value = "opg" & aryArea(i)
For i = 0 To 7
Me(j).Value = DLookup(fld1(1 + i), "tblAreaTemp", "ScenarioID = " _
& g_intScenarioID)
If Me(j).Value > 0 Then
m_intCount = m_intCount + 1
End If
Next i

MsgBox "The count is " & m_intCount
 
Why use a loop? Just set each one in a separate line of code.
Also, be aware that DLookup is quite slow

-Dorian
 
What is fld1(1 + i) supposed to be? (for that matter, was is fld1 supposed
to be?)

The first argument of DLookup must be a string that represents the name of a
field in the table or query represented by the second argument.
 
I was trying to use a field index, but if it has to be a string that explains
my error.

Thanks.
 

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

Back
Top