DSum help

B

Bobby.Dannels

Being new to vba and Access, I think what I am trying to do is out of
my realm of understanding. I have two querries that query the same
table "QtyUsed". One query "QtyUsed6Mo" filters results by the date
field to records within the last 6 months. The other "QtyUsedYr"
filters within the last year. I want to create a DSum that will add
all the records in the query that have the same "NSN" and add the qty
"Used" to another table "DataTable.QtyUsed6Mo and DataTable.QtyUsedYr"
 
J

Jeanette Cunningham

Bobby,
Usually it is not good practice to store these calculations in a table.
You can always use the query, both queries 6Mo and Yr to give the calculated
values for a form's recordsource or for a report.
Using the query instead of a table, gives you the most up-to-date value for
the values. It also avoids the problem that can happen when one of the dates
is edited and this changes the value for QtyUsed. If the calculation was in
a table, you would need to change the value in the table every time one of
the dates was edited - that is too much work - much easier to just use the
query.
Note: there are some databases that do need to store a calculated value in a
table, but this is not very frequent.

Jeanette Cunningham
 
B

Bobby.Dannels

Can I not write a code that will update the table every time the value
in the query changes? If not, how would I write the code that I need
to have the form pull straight from the query?
 
B

Bobby.Dannels

Can I not write a code that will update the table every time the value
in the query changes? If not, how would I write the code that I need
to have the form pull straight from the query?

More importantly how would I get the query to filter the table by the
nsn that is currently being displayed in the form?
 
J

Jeanette Cunningham

Yes you could write code to do this. What happens if someone imports data
into the table? It is not best practice to store the calculation.
To have the form pull straight form the query - you would do a DLookup to
the query and put the result in a label or textbox.

Jeanette Cunningham
 
J

Jeanette Cunningham

In design view of the query, in the criteria row for nsn, type the correct
syntax for the name of the nsn control on the form.
Forms!YourFormName!TheControlName - assuming a form that is not a subform.
As long as the form is open, the query will be able to get the nsn value
from the form.

Jeanette Cunningham

Can I not write a code that will update the table every time the value
in the query changes? If not, how would I write the code that I need
to have the form pull straight from the query?

More importantly how would I get the query to filter the table by the
nsn that is currently being displayed in the form?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DSum Question 2
DSUM in Form 4
need help with DSUM 3
dsum sytax error 5
This is hard to explain 11
Dsum Issues 0
DSum Question 1
DSum #Error 4

Top