This is the last version I saw. I see a syntax error
=DLookUp("[AFPercentage]","CostPerformanceAwardFee", "[CLIN] = " & [caclin]
& ")")
Should be
=DLookUp("[AFPercentage]","CostPerformanceAwardFee", "[CLIN] = " & [caclin]
& ")
Now to clearify:
[AFPercentage] and [CLIN] should be fields in the table/query
CostPerformanceAwardFee.
[calcin] should be the name of a control in your report.
The syntax assumes [CLIN] is a numeric field.
The code should be in the control source of a control on the form.
Is this all correct?
--
Dave Hargis, Microsoft Access MVP
:
No problem, questiosn are good - especially if they lead to answers.... For
this particular dlookup, it is in the report.
:
Sorry to ask so many questions, but I am a little confused.
Is the DLookup in the form or in the report?
--
Dave Hargis, Microsoft Access MVP
:
Dave,
the report is run adhoc and summarizes/groups data based on the field CACLIN
(data source is a query). The report (hopefully) will be able to lookup the
AFPercentage associated with the current grouping of CACLIN and display a
calculated value using the AFpercentage returned from the dlookup.
Dan
:
I don't rememer if you said earlier it was for the control source of a
control, but the reason the Me doesn't work in that context is that the
DLookup goes to Jet as an SQL statement. Jet will not understand Me, so you
have to drop it or fully qualify it with [Forms]![FormName]![ControlName].
As to running the report and getting the error, How are you opening the
report? It may be it is not understanding the reference to the control on
the form.
--
Dave Hargis, Microsoft Access MVP
:
Dave (and or Doug),
I'm still working to get the kinks out, so I've simplified my dlookup to
include just 1 criteria. The statement in the datasource for the control on
the report reads:
=DLookUp("[AFPercentage]","CostPerformanceAwardFee", "[CLIN] = " & [caclin]
& ")")
where: AFPercentage and CLIN are fields in the table
CostPerformanceAwardFee. The field "caclin" is the name of the control in the
report that I'm trying to find the corresponding AFPercentage for. The
variant between the statement above and the sample you provided is I dropped
the "me." from the reference to "caclin" since it kept changes the reference
to from me.caclin to [me].[caclin] and wnating a value for "me". When I run
the report, the result is #error. Your thoughts?
Thanks, Dan
:
Had not noticed you use Doug.
I do really respect your knowledge of Access and your ability to cut through
the clutter. I have learned a lot from you and you keep me on my toes. I
always thing "If I screw this up, I will hear from Doug"
--
Dave Hargis, Microsoft Access MVP
:
<blush>
But why does everyone refuse to notice that it's Doug among friends? <g>
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
LOL
I have the same problem.
There is a frequent MVP poster named Douglas J. Steele whom I consider to
be
not only the most knowledgable person I know when it comes to Access, but
also has the best approach to most problems.
--
Dave Hargis, Microsoft Access MVP
:
Oops, no really meant you Dave (some one named Doug stepped into my
ioffice
as I started to compose the question). Multi-tasking will be the end of
me
soon enough....
Dan
:
Doug?
If you are confusing me with Douglas J. Steele, I am honored and he is
probably upset
You can use the same DLookup in the report. You would put it in the
control
source of a text box. Instead of referencing the control names on the
report
(val1, val2), you would reference the corresponding controls on the
report.
--
Dave Hargis, Microsoft Access MVP
:
Doug, a followup question. If I needed to do something similar during
the
generation of a report, woudl the dllokup work? In the report val1 &
val2
are populated, but would be used inm the dlookup against the same
table.
thanks,Dan
:
The DLookup should do it for you:
DLookup("[Field3]", "MyTable", "[Field1] = " & Me.Val1 & " And
[Field2] <
" & Me.Val2])
A couple of notes:
The syntax above assumes Field1 and Field2 are both numeric. If
they are
not, you will need to modify the code to include the delimiters for
other
data types.
DLookup will return Null if no match is found.
--
Dave Hargis, Microsoft Access MVP
:
I have a table with 3 fields (Field1, Field2, Field3). On a
form, there are
2 fields, Val1 and Val2. I need to be able to search the table,
returning
the value in Fields 3 where Val1 = Field1 and Val2 < Field2. The
table is
sorted by Field1 ascending and Field2 descending.
Thanks in advance, Dan