A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Dlookup a range with multiple criteria



 
 
Thread Tools Display Modes
  #1  
Old June 29th, 2009, 04:22 PM posted to microsoft.public.access.queries
kazzaw
external usenet poster
 
Posts: 5
Default Dlookup a range with multiple criteria

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much
  #2  
Old June 29th, 2009, 04:35 PM posted to microsoft.public.access.queries
Klatuu
external usenet poster
 
Posts: 7,074
Default Dlookup a range with multiple criteria

first,
And [DISCOUNT CODE] & "[code]"
makes no sense. There is no logical operator in this part of the code.

second, I am surprise it works at all. This part has incorrect syntax:
[Price] & " Between [start] And
[end]"


It should be
[Price] & " Between " & [start] & " And " & [end]

Also, where are code, start and end identified?

--
Dave Hargis, Microsoft Access MVP


"kazzaw" wrote:

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much

  #3  
Old June 29th, 2009, 05:08 PM posted to microsoft.public.access.queries
kazzaw
external usenet poster
 
Posts: 5
Default Dlookup a range with multiple criteria

Thanks for the quick reply, sorry if I am confusing matters, to clarify

1. I have a table with markup start and end ranges, discount codes and
percentages
2. In a further table I have price and discount code

the object of the problem is i want the dlookup to find the price from table
2 in table 1 whilst matching the discount code from both tables.

The price field is a numeric field and the discount code a text field.

The first part of the code did pick up the percentage ratio ok, i found
similar code in this discussion group and amended it accordingly, or so I
thought:-

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]")

it was adding the discount code part of the criteria that didn't work, maybe
I have it all wrong it and it was pure chance I got a result.

I have also tried adding the = between the code and discount code and it
still doesn't work.

Help please




"kazzaw" wrote:

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much

  #4  
Old June 29th, 2009, 06:04 PM posted to microsoft.public.access.queries
Klatuu
external usenet poster
 
Posts: 7,074
Default Dlookup a range with multiple criteria

Please look at the syntax here. The criteria has to be sent to the DLookup
as a string.
DLookUp("[markup]","[markup percentages]", "[Price] Between " & [start] & "
And " & [end] & " And " [DiscountCode] = """ & """[code]""")

But even then, it is not complete, because you did not say where start, end,
and Code are defined. They should be controls on your form or a variable you
have saved somewhere.
--
Dave Hargis, Microsoft Access MVP


"kazzaw" wrote:

Thanks for the quick reply, sorry if I am confusing matters, to clarify

1. I have a table with markup start and end ranges, discount codes and
percentages
2. In a further table I have price and discount code

the object of the problem is i want the dlookup to find the price from table
2 in table 1 whilst matching the discount code from both tables.

The price field is a numeric field and the discount code a text field.

The first part of the code did pick up the percentage ratio ok, i found
similar code in this discussion group and amended it accordingly, or so I
thought:-

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]")

it was adding the discount code part of the criteria that didn't work, maybe
I have it all wrong it and it was pure chance I got a result.

I have also tried adding the = between the code and discount code and it
still doesn't work.

Help please




"kazzaw" wrote:

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much

  #5  
Old July 13th, 2009, 10:51 AM posted to microsoft.public.access.queries
kazzaw
external usenet poster
 
Posts: 5
Default Dlookup a range with multiple criteria

I have just got back to working on this dlookup and you are quite correct in
saying that the syntax is incomplete, I will try to explain exactly what I
want in the hope that you can help me further.

I have one table (updated today) that contains a list of prices with codes,
the fields that I want to lookup elsewhere are price and discount code.

The second table called markup percentages, the one I want to lookup from
has a list of markup codes also called discount code (similar to the one in
table1) and then price range fields start and end (so price range may start
at 20.00 and end at 200.00 but the actual price I want to lookup may 50) the
field I want to return from this table is called markup.

In short I want to find the markup value from markup percentages table based
on the price (which will be within the range start and end) and discount code
in my updated today table.

This syntax DLookUp("[Markup]","Markup Percentages","[Discount Code] = '" &
[Discount Code] & "'") finds a markup based only on the code but when I try
to add the code for looking up the price range it does not recognise my
referencing to start and end, the code I used was: Expr2:
DLookUp("[Markup]"," Markup Percentages",[Price] Between [Markup
Percentages]![start] And [Markup Percentages]![end])

Any help would be greatly appreciated, thanks.



"Klatuu" wrote:

Please look at the syntax here. The criteria has to be sent to the DLookup
as a string.
DLookUp("[markup]","[markup percentages]", "[Price] Between " & [start] & "
And " & [end] & " And " [DiscountCode] = """ & """[code]""")

But even then, it is not complete, because you did not say where start, end,
and Code are defined. They should be controls on your form or a variable you
have saved somewhere.
--
Dave Hargis, Microsoft Access MVP


"kazzaw" wrote:

Thanks for the quick reply, sorry if I am confusing matters, to clarify

1. I have a table with markup start and end ranges, discount codes and
percentages
2. In a further table I have price and discount code

the object of the problem is i want the dlookup to find the price from table
2 in table 1 whilst matching the discount code from both tables.

The price field is a numeric field and the discount code a text field.

The first part of the code did pick up the percentage ratio ok, i found
similar code in this discussion group and amended it accordingly, or so I
thought:-

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]")

it was adding the discount code part of the criteria that didn't work, maybe
I have it all wrong it and it was pure chance I got a result.

I have also tried adding the = between the code and discount code and it
still doesn't work.

Help please




"kazzaw" wrote:

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much

  #6  
Old July 13th, 2009, 11:11 AM posted to microsoft.public.access.queries
kazzaw
external usenet poster
 
Posts: 5
Default Dlookup a range with multiple criteria

i think i got the price and start and end fields the wrong way around, but
this change still returns error as the result:

Expr2: DLookUp("[Markup]"," Markup Percentages"," Between [start] and [end]
= " & [price])


"Klatuu" wrote:

Please look at the syntax here. The criteria has to be sent to the DLookup
as a string.
DLookUp("[markup]","[markup percentages]", "[Price] Between " & [start] & "
And " & [end] & " And " [DiscountCode] = """ & """[code]""")

But even then, it is not complete, because you did not say where start, end,
and Code are defined. They should be controls on your form or a variable you
have saved somewhere.
--
Dave Hargis, Microsoft Access MVP


"kazzaw" wrote:

Thanks for the quick reply, sorry if I am confusing matters, to clarify

1. I have a table with markup start and end ranges, discount codes and
percentages
2. In a further table I have price and discount code

the object of the problem is i want the dlookup to find the price from table
2 in table 1 whilst matching the discount code from both tables.

The price field is a numeric field and the discount code a text field.

The first part of the code did pick up the percentage ratio ok, i found
similar code in this discussion group and amended it accordingly, or so I
thought:-

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]")

it was adding the discount code part of the criteria that didn't work, maybe
I have it all wrong it and it was pure chance I got a result.

I have also tried adding the = between the code and discount code and it
still doesn't work.

Help please




"kazzaw" wrote:

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much

  #7  
Old July 13th, 2009, 12:13 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 2,364
Default Dlookup a range with multiple criteria

If you are going to use DLookup, you might try

DLookUp("[Markup]","[Markup Percentages]",[Price] & " Between [start]
and [end]")

and if you also need to get the markup based on both price and discount
code try:
DLookUp("[Markup]","[Markup Percentages]",[Price] & " Between [start]
and [end] And [Discount Code] = '" & [Discount Code] & "'")

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


kazzaw wrote:
i think i got the price and start and end fields the wrong way around, but
this change still returns error as the result:

Expr2: DLookUp("[Markup]"," Markup Percentages"," Between [start] and [end]
= " & [price])


"Klatuu" wrote:

Please look at the syntax here. The criteria has to be sent to the DLookup
as a string.
DLookUp("[markup]","[markup percentages]", "[Price] Between " & [start] & "
And " & [end] & " And " [DiscountCode] = """ & """[code]""")

But even then, it is not complete, because you did not say where start, end,
and Code are defined. They should be controls on your form or a variable you
have saved somewhere.
--
Dave Hargis, Microsoft Access MVP


"kazzaw" wrote:

Thanks for the quick reply, sorry if I am confusing matters, to clarify

1. I have a table with markup start and end ranges, discount codes and
percentages
2. In a further table I have price and discount code

the object of the problem is i want the dlookup to find the price from table
2 in table 1 whilst matching the discount code from both tables.

The price field is a numeric field and the discount code a text field.

The first part of the code did pick up the percentage ratio ok, i found
similar code in this discussion group and amended it accordingly, or so I
thought:-

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]")

it was adding the discount code part of the criteria that didn't work, maybe
I have it all wrong it and it was pure chance I got a result.

I have also tried adding the = between the code and discount code and it
still doesn't work.

Help please




"kazzaw" wrote:

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much

  #8  
Old July 13th, 2009, 12:34 PM posted to microsoft.public.access.queries
kazzaw
external usenet poster
 
Posts: 5
Default Dlookup a range with multiple criteria

John you are a star, this has worked perfectly, thank you so much.

Karen

"John Spencer" wrote:

If you are going to use DLookup, you might try

DLookUp("[Markup]","[Markup Percentages]",[Price] & " Between [start]
and [end]")

and if you also need to get the markup based on both price and discount
code try:
DLookUp("[Markup]","[Markup Percentages]",[Price] & " Between [start]
and [end] And [Discount Code] = '" & [Discount Code] & "'")

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


kazzaw wrote:
i think i got the price and start and end fields the wrong way around, but
this change still returns error as the result:

Expr2: DLookUp("[Markup]"," Markup Percentages"," Between [start] and [end]
= " & [price])


"Klatuu" wrote:

Please look at the syntax here. The criteria has to be sent to the DLookup
as a string.
DLookUp("[markup]","[markup percentages]", "[Price] Between " & [start] & "
And " & [end] & " And " [DiscountCode] = """ & """[code]""")

But even then, it is not complete, because you did not say where start, end,
and Code are defined. They should be controls on your form or a variable you
have saved somewhere.
--
Dave Hargis, Microsoft Access MVP


"kazzaw" wrote:

Thanks for the quick reply, sorry if I am confusing matters, to clarify

1. I have a table with markup start and end ranges, discount codes and
percentages
2. In a further table I have price and discount code

the object of the problem is i want the dlookup to find the price from table
2 in table 1 whilst matching the discount code from both tables.

The price field is a numeric field and the discount code a text field.

The first part of the code did pick up the percentage ratio ok, i found
similar code in this discussion group and amended it accordingly, or so I
thought:-

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]")

it was adding the discount code part of the criteria that didn't work, maybe
I have it all wrong it and it was pure chance I got a result.

I have also tried adding the = between the code and discount code and it
still doesn't work.

Help please




"kazzaw" wrote:

I am trying to calculate markup based on a price range and code number, when
I use the range part of the code it runs fine but as soon as I add the
discount code field reference it returns the same number for all fields, the
code I have in my query is

DLookUp("[markup]","[markup percentages]",[Price] & " Between [start] And
[end]" And [DISCOUNT CODE] & "[code]")

Any help would be much appreciated as I have been searching forums and
discussions groups for too long now.

Thanks very much


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.