Solved

Using Dlookup with multiple fields to display one field

Posted on 2013-10-30
13
307 Views
Last Modified: 2013-11-04
I have a Table [IEGDate] with 4 primary key fields; [Effective], [HHSize], [Frequency], [IncomeType] with a  non-primary key field [IncomeThreshold].

I also have a form [IEChild], with fields [HHSize], [HHIncome] and [Frequency].  I need to lookup these 3 fields in the [IEGDate] table and return the [IncomeType] on this form.  The [HHIncome] field would correspond with the [IncomeThreshold].  In summary, the fields [HHSize] and [Frequency] must match and the [HHIncome] must be equal to or less than the [IncomeThreshold] to display the [IncomeType].  If the [HHIncome] is greater than the [IncomeThreshold], display "No".

Can you assist?
0
Comment
Question by:softsupport
  • 6
  • 6
13 Comments
 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
I think you would be much better off doing this filtering in a query used for the form's record source, or possibly a subform.  It is a lot easier to work with filters and calculations in the Query Designer, as opposed to the control source of a textbox on a form.
0
 

Author Comment

by:softsupport
Comment Utility
I would like to use the DLookup feature, ( or some other lookup) to search the table and display results, if it is possible.
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
This looks up one field "Entity" in table "comma"  with condition of 2 fields Year and Case:

 DLookup("Entity", "comma", "[Year]='" & Me.Year & "' AND [Case]='" & Me.Case & "'")

"Using Dlookup with multiple fields to display one field"
Multiple fields go in the where condition.
0
 

Author Comment

by:softsupport
Comment Utility
Thank you for the Dlookup example above, but I would like to lookup 3 fields, returning 1.
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
"Thank you for the Dlookup example above, but I would like to lookup 3 fields, returning 1. "

Do you mean if we have a table x(a, b, c, d)
a b c d
1 1 1 b
1 1 2 c
2 2 2 d

If you look for record with 1, 1, 1 do you expect to report back the value b?
Using a where clause will report the same result.

So what exactly you are looking for?

Talk as you would tell some one over the phone what to do to get the expected result.
0
 

Author Comment

by:softsupport
Comment Utility
In a form [Family], I have 3 fields, [HSize], [HIncome], [Frequency]

In a table [IEG]I have 4 fields [HSize], [IncomeThreshold], [Frequency], [Type]

I would like the database to compare the fields in [Family] table to fields in [IEG] table.

[Family]![HSize] must equal [IEG]![HSize]
[Family]![Frequency] must equal [IEG]![Frequency]
[Family]![HIncome] must be less than or equal to [IEG]![IncomeThreshold]

If it meets all 3 criteria, display the [IEG]![Type], if not display N.


Hope this clarifies my request.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 500 total points
Comment Utility
Yes this is the same case, look for [IEG]![Type]

DLOOKUP ("[Type]", "IEG", " [IEG]![HSize]='" & [Family]![HSize] & "' AND [Frequency]='" & [Family]![Frequency] & "' AND  [IncomeThreshold] >='" & [Family]![HIncome] &"'")

Remove single quotes  if fields are numeric.
0
 

Author Comment

by:softsupport
Comment Utility
Works perfectly, except

 "If it meets all 3 criteria, display the [IEG]![Type], if not display N."
Can I display on the [Family] form
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Nz(DLOOKUP ("[Type]", "IEG", " [IEG]![HSize]='" & [Family]![HSize] & "' AND [Frequency]='" & [Family]![Frequency] & "' AND  [IncomeThreshold] >='" & [Family]![HIncome] &"'"),"N")
0
 

Author Comment

by:softsupport
Comment Utility
And to show on family form?  Use unbound field?
0
 
LVL 30

Accepted Solution

by:
hnasr earned 500 total points
Comment Utility
"And to show on family form?  Use unbound field? "

Yes, you may use it in proper place:

TxtBox1 = Nz(DLOOKUP ("[Type]", "IEG", " [IEG]![HSize]='" & [Family]![HSize] & "' AND [Frequency]='" & [Family]![Frequency] & "' AND  [IncomeThreshold] >='" & [Family]![HIncome] &"'"),"N")

Or you may set the control source for a TextBox as =Nz(DLOOKUP ("[Type]", "IEG", " [IEG]![HSize]='" & [Family]![HSize] & "' AND [Frequency]='" & [Family]![Frequency] & "' AND  [IncomeThreshold] >='" & [Family]![HIncome] &"'"),"N")
0
 

Author Closing Comment

by:softsupport
Comment Utility
Thank you so very, very much!!!
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Welcome!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now