Solved

Using Dlookup with multiple fields to display one field

Posted on 2013-10-30
13
311 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
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

860 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