473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using multiple criteria to lookup values in related records

Hi - newbie here, be gentle. In Access 2003, I've created a report (based on a query) to produce mailing labels for all records where [Contact Type] = "Community". [Contact Type] is a combo-box field with the values coming from a seperate table.

Problem is, some of these don't have addresses (ie. [Address 1], [Address 2] and [Post Code] are null). So I want to use the address of the Administrator for that community. This information is in records where [Contact Type] = "Administrator" and [Community] = whatever the community with the blank address is. [Community] is also a combo-box based on another table.

To do this, I wrote the following DLookUp for the first line of the address that I will place within an Nz() or If(IsNull()) expression when it's working:

=DLookUp("[Address 1]","[Main]","[Community] = " & Reports!Community!Community And "[Contact Type] = 'Administrator'")

However, this only gives the first line of the address of the first record in the table. When tested in the Immediate pane in VB I get "Type mismatch". If I test the same expression with only the first criteria I get "You canceled the previous operation", with only the second criteria I get "Data type mismatch". But if I test the criteria by themselves (seperately) they seem to work.

In summary, I seem to be getting the syntax for multiple text criteria of a DLookUp expression wrong .

Anyone got any ideas? I know the best thing would be a Recordset but I havent got a clue how to do them. Sorry for the long post, hope it makes sense, and thanks very much in advance!
Aug 12 '08 #1
2 5537
Stewart Ross
2,545 Expert Mod 2GB
Hi, and welcome to Bytes.

For the immediate problem with your DLookup syntax, here is a revised version which corrects the problem with your AND clause.

Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[Address 1]","[Main]","[Community] = " & Reports!Community!Community & " And [Contact Type] = 'Administrator'")
However, as you say this only returns one line of the address -so you will need to repeat it for the other lines.

I would instead use a query in which you join the base table to the table 'Main' storing the community contact details. You would still need to select the community administrator address if the other address is null, but this can be done using IIF statements or similar in the revised query to return one or other address line, like this:
Expand|Select|Wrap|Line Numbers
  1. rev_address1: IIF(IsNull([Address 1]), [admin address 1], [Address 1])
  2. rev_address2: IIF(IsNull([Address 1]), [admin address 2], [Address 2])
The test in each case is for null in the first line of the address - later lines may be intentionally null (if the address is short).

When I do this sort of thing myself (in selecting between work and home addresses, for instance) I use a custom function in VBA to return the correct address line to the underlying query concerned. It is more efficient by far than using IIFs, but I think at present you will find the IIFs much easier to implement.

-Stewart
Aug 12 '08 #2
Thanks for that - turned out to be a combination of a wrong AND clause as you said, as well as the fact that both dropdown fields were being indexed by their AutoNumber ID rather than the option itself. Cheers!
Aug 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: amywolfie | last post by:
Hi All: I would like to run a report based on criteria from 3 unbound combo boxes located on a parameter form (combo boxes are: cboCuisine, cboLocation, and cboRestaurant) The present code...
3
by: Tripp Knightly | last post by:
I have a lookup table from which I want to categorize various bands of customer net income. Some of the income is positive, some is negative. The bands vary in size (ie, <500, -200 to 0, 100 to...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
8
by: Christine Henderson | last post by:
I have a problem using the above function in the following simplified circumstance: In the lookup table called "Klms Travelled" I have 3 fields, eg: Receiver Name Receiver Suburb ...
4
by: Robert Bravery | last post by:
Hi all, I have now correctly set up my dataset and two grids, so that the parent navigates the child. THe thing is that the child table is actually a lookup type table. It lists billing types for...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
2
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.