I think I found the post you lost where that was answered.... Is this what
you are looking for?
Your question was answered in the previous thread, which you say you "cannot
find". I will repost the answer here, though I'm not sure how you'll "find"
this thread either?
This type of query is more easily built using SQL View rather than design
view. But, let me give you the full SQL statement of the query and then I'll
discuss how to build it in design view -- note that you didn't tell us the
name of the second table, so I'm using a generic name (
WhateverTheNotherTableIsNamed ) for it in this statement:
SELECT [Salaries Register].GROSS,
(SELECT T.[Tax Amount]
FROM WhateverTheNotherTableIsNamed AS T
WHERE [Salaries Register].GROSS Between
T.PayRangeLow And T.PayRangeHigh) AS TaxAmount
FROM [Salaries Register];
To do this in design view, add the [Salaries Register] table to the grid.
Put the GROSS field on the grid.
Then, in the first empty column, put this entire expression in the Field:
box (be sure to replace the generic table name with the real name of your
other table):
TaxAmount: (SELECT T.[Tax Amount] FROM WhateverTheNotherTableIsNamed AS T
WHERE [Salaries Register].GROSS Between T.PayRangeLow And T.PayRangeHigh)
An alternative way to do this query is to use the DLookup function for the
TaxAmount field value:
SELECT [Salaries Register].GROSS,
DLookup("Tax Amount", "WhateverTheNotherTableIsNamed",
[Salaries Register].GROSS & " Between
[PayRangeLow] And [PayRangeHigh]") AS TaxAmount
FROM [Salaries Register];
In this example, the second column in design view would have this expression
in the Field box (again, remember to replace the generic table name with the
real name):
TaxAmount: DLookup("Tax Amount", "WhateverTheNotherTableIsNamed", [Salaries
Register].GROSS & " Between [PayRangeLow] And [PayRangeHigh]")
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" - Tremors
II
Christina said:
Thanks very much. I fixed the data and it works now. Would youplease
help
me with one for the social security table. Allfields arethe same.
Thanks
Gina Whipp said:
No problem... hopefully that will solve the problem!
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" -
Tremors
II
Christina said:
Thank you. I will have to check the tables again when I go to work in
the
morning. Thanks so much.
:
In the new data what happens if I make 385.69? (I just tested and I
fall
nowhere!) Your ranges on the new data don't account very every Gross.
Have
you looked to see where they Gross falls?
Also, when you stopped working does that mean you go no results?
Because
you might want to look at the Gross amounts as I indicated above.
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" -
Tremors
II
This is all the old data. I did not change the data type, I only
copied
and
pasted the new figures from an excel table.
PayRangeLow PayRangeHigh TaxAmount
$100.00 $199.00 $8.30
$200.00 $299.00 $1.35
$300.00 $399.00 $1.95
$400.00 $402.61 $3.15
$500.00 $599.00 $4.75
$600.00 $699.00 $6.35
$700.00 $799.00 $7.95
$800.00 $899.00 $9.55
$402.62 $402.67 $4.51
These aresome of the new data, as the real data is 616 rows long,
whereas
the old data was just 9 rows.
PayRangeLow PayRangeHigh TaxAmount
$385.62 $385.67 $0.26
$386.62 $386.67 $0.51
$387.62 $387.67 $0.76
$388.62 $388.67 $1.01
$389.62 $389.67 $1.26
$390.62 $390.67 $1.51
$391.62 $391.67 $1.76
$392.62 $392.67 $2.01
:
Christina,
You said beofre it worked now it doesn't. Please provide sample
data
before
and after. Things don't just stop working so there might be a clue
in
the
data. And have you confirmed that the fields are set to Currency?
Will
also need the data type of the other fields in the Expression
below.
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" -
Tremors
II
All fields in the Income Tax table are set to currency. However
the
real
data I copied from an excel spreadsheet into the same table, and
the
fields
are still set to currency.
:
Going to need to see a sample of the data that did work and a
sample
that
does not work; ie...
Income Tax table
Field1 - Text or Numeric
Field2 - Text or Numeric
etc...
--
Gina Whipp
"I feel I have been denied critical, need to know,
information!" -
Tremors
II
message
I am sorry. I have a query with gross field from the Salaries
Register
table and this code in the blank column in Field . The
income
tax
table
with dummy records was already made, when I used the formula
and
it
worked.
But when I change the data to the correct data in the income
tax
table,
it
does not return any data.
What am I doing wrong. I also tried imitating the same code
and
substitute
with th Social Security Table, and it does not work.
Grateful for your help.
:
The formula you provided is not the DLookup, where is that
statement?
Also
where is this Income Tax: formula, in a query?
--
Gina Whipp
"I feel I have been denied critical, need to know,
information!" -
Tremors
II
message
Thanks. Also can you please help me with this. I created
two
tables,
one
with Salary Particulars and Tax Payable called Income Tax.
In
the
Income
Tax
tBle I had dummy data. My dlookup works withe the dummy
data,
but
when
I
go to
update the income tax table, it does not return an data.
Here
is
the
formula
Income Tax: (SELECT T.[TaxAmount] FROM IncomeTax AS T
WHERE
[PayRoll
Table].GROSS Between T.PayRangeLow And T.PayRangeHigh)
I aslo need to do one for social security for a table named
social
security
table, with the same fields. I tried but cant get it to
work.
Somebody
helped me with that formula, but I cant find the post.
By the way this is not Tax for US,as the other person had a
question
with
my
table.
Thanks for your help
:
You cannot change an already populated field into an
AutoNumber.
You
have
to create a new field, select AutoNumber and set it as the
Primary
Key
and
then place that field on the form.
--
Gina Whipp
"I feel I have been denied critical, need to know,
information!" -
Tremors
II
message
Can you go back and make the field to be auto number,
after
making
the
table
and form?
Thanks
:
Christina,
Is the Primary Key you created an AutoNumber? Because
other
then
that
your
form will not populate it, you will have have to
generate
some
code
to
populate it.
--
Gina Whipp
"I feel I have been denied critical, need to know,
information!" -
Tremors
II
in
message
I made a from to key in data to a form. Afterwards I
decided
to
create
a
Primary key for the table. My form however is not
populating
the
field.
Please help. Thanks