Solved

Using Dlookup with multiple fields to display one field

Posted on 2013-10-30
13
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 39612568
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
ID: 39612646
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
ID: 39612886
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Expert Comment

by:hnasr
ID: 39615378
"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
ID: 39616756
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
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 500 total points
ID: 39617999
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
ID: 39620563
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
ID: 39620642
Nz(DLOOKUP ("[Type]", "IEG", " [IEG]![HSize]='" & [Family]![HSize] & "' AND [Frequency]='" & [Family]![Frequency] & "' AND  [IncomeThreshold] >='" & [Family]![HIncome] &"'"),"N")
0
 

Author Comment

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

Accepted Solution

by:
hnasr earned 500 total points
ID: 39620672
"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
ID: 39622383
Thank you so very, very much!!!
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39623226
Welcome!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

726 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