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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report Intelligence 1

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
US
I have a need to add a field of data to a report only if the criteria for another field equals one of five possible values. Otherwise, this information would be blank.

I am thinking of utilizing the dLookup feature. We have a database of parts that are either purchased, custom, modified or painted. If the part on the database is painted, dLookup should lookup that parts manufacturer in the table.

The problem is, where is this coded? I believe it would look something like this...

If Code.Value = "Painted" Then
Text117.Value = DLookUp("[ManufacturedBy]","tblPartsListing"," [PartNo] = '" & [Reports]![rptManufactured Parts List]![PartNo] & "' ")

Else
Text117.Value = Null
End If


There really is not much information out about VBA with reports, at least compared to forms - where most of my stuff gets customized. Are you aware of a good overview source on this?

Thankyou in advance for your help.



 
I have another suggestion:
The Dlookup function can slow the report and it is not nessesary in your case.
The more appropriate way is to use the iif() in the field's ControlSource.
I'd put that field on the report and put in the ControlSource property of the field this code:
=iif([criteriaField]=wantedValue, valueOfNeededField, "")

I'm willing to provide more explanations if needed.

Good luck
 
Thankyou:

I do have one more question about this topic. The value of the needed field is based on the DLOOKUP criteria. I do not think I can use DLOOKUP within the iif command. What would be toe syntax? Also, is the , "" at the end of the iif the else condition?
 
You can use the DLookup expression freely in the IIF() function and yes, the "" is in the "else" condition. I'll rewrite the code you've written to the IIF() function:
=IIF(
Code:
 = "Painted",DLookUp("[ManufacturedBy]","tblPartsListing"," [PartNo] = '" & [Reports]![rptManufactured Parts List]![PartNo] & "' "), Null)

The iif() function is very usefull in forms and reports where one field's value can depend on other fields value or any expression value. Also, you can use it in VBA instead of if..then..else..
 
I think I have it working satisfactorily. Thanks again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top