Queries :: Getting Required Data Using Query For Calculations To Be Used Later?
Nov 7, 2014
I've been trying unsuccessfully for weeks to try and query a usable data set that would later be used for calculated values in a report.
I'm building a Hospital Acquired Infections Database for my facility to record data and process reports automatically. Previously, I built the system in Excel using VBA and userforms, but the size of the file has become too cumbersome, and now takes too long to process my reports.
So here's the issue.
UNIT_DATA TABLE:
UNIT
INF_MONTH
INF_YEAR
PT_DAYS
CVC_DAYS
IUC_DAYS
VENT_DAYS
APV_DAYS
PT_LEVEL TABLE (There are many fields in this table for recording purposes but I will only list the ones I need for reporting purposes):
UNIT
INF_STE_MAJ
SPECIF_SITE
INF_MONTH
INF_YEAR
So the important numbers I can't seem to collect are the total number infections per month from the PT_LEVEL Table for only select SPECIF_SITE infections.
The UNIT_DATA Table is a monthly collection for the 5 metrics (PT_DAYS, CVC_DAYS, IUC_DAYS, VENT_DAYS, APV_DAYS) regardless of whether or not the number for each is zero. Every unit in the database will have a record for each month and year.
The PT_LEVEL Table will only have records if and when a patient develops an infection. This means there is no cumulative monthly data for the PT_LEVEL Table Data based on SPECIF_SITE infection type.
I need to first do a roll up count for every month and year in the database, for which I was initially trying to use the UNIT_DATA table for since it contains every month and year. The problem is when I try to query the SPECIF_SITE from PT_LEVEL, I can get the number of Infections for months where infections where present for each unit and null values, for each month, and each year in UNIT_DATA, but when I include a where condition to narrow the view to only selected SPECIF_SITE's it only shows data for that SPECIF_SITE for months where they occured.
I need a cummulative monthly aggregation of the totals for a selection of SPECIF_SITE infections, for every unit, for every month, and every year, since July 2010.
I am trying to add calculations to queries based on columns in the query... it seems to randomly expect 'Expression' or 'Group by' as column types, and Im having to create 3 sets of queries following on from each other to de-dupe data and allow filters on calculated values.
Also I've got a function which turns a date into a quarterly cohort, e.g. Oct 2013 -> 20134. I use ot on a lot of dates. I created a VBA function, CohortQ used as follows in queries:
Code: Function CohortQ(InputDate As Date) As Integer If InputDate = 0 Then CohortQ = 0 Exit Function End If
[Code] .....
But when I run it on a date field, it gives me a data mismatch error. I can't step through as it's working on 600K rows. If I put the function into the query,
Is there any way I can use data in the row as a column header ? I only have 1 row of data which i want to use as a header to I can link it to other tables/queries.
I need to do a calculation on the RESULTS of a query. Each record in the table I'm querying has a date stamp. I have a query that produces a list of the newest records for each machine. I want to calculate how old each of those records is based on today's date.
So far when I try to include the calculation in that query, it returns all the records instead of the newest ones. This makes me think I'm doing something fundamentally incorrect. The calculation is affecting the query results where I just want to do the calculation on the results. What I'm trying to ultimately do is have a way for the users to see a list of machines that are overdue for a certain procedure. I was thinking of putting a button on a form that will run the query and present the list, perhaps with some conditional formatting highlighting the machines that are overdue, etc. Do I need to just use 2 queries?
I am trying to use SQL to run queries in our access database in order to (hopefully) speed things up. I'm trying to create code that basically takes data from one table and inserts it into another whilst doing calculations on the data.
However I can't get past this:
Code: Private Sub Test_Click() Dim strSQL As String
I have solved the problems getting values on the subform. I have not in getting values on the subform.For instance, on the one titled phone use the formula in the tutorial is:
=[sbfCustomerRoomUse].[Form]![txtTotalPhoneUse]
#Error results when the doc is put into a form mode.
Now when I input each value in the equation above separately.I still get no entry.
For " = sbfCustomerRoomUse" , I get #Error; and for "= txtTotalPhoneUse", I get #Name.
CustomerRoomUse and txtTotalPhoneuse are from the subform that was dropped into the customer form in a previous step. It shows that explicitly when designed sbfCustomerRoomUse on the main that CustomerRoomUse come from a subform. This does not seem to need to be done with txtTotalPhoneuse, and I am not sure why. Neither one gives me a desired calculation result.
I have a query that I run to extract some values for calculations. Its run on an event based on a dropdown selection. At the moment, I run via:
Code: DoCmd.OpenQuery "CallMidprice"
and then close it. this seems to take more time than is necessary when I only want to refresh the results.Open query without close, switches to the table but doesn't update until I press F5.When I try requery I get an error. "Runtime error '2109': There is no field named 'CallMidprice' in the current record.
Requery without 'Callprice' seems to requery my form.
I'm using an input mask of: AAA-AAAaaa This allows three Characters, followed by a "-" followed by three more characters, followed by optional three more characters.
My problem is that the "-" is not actually part of the data. It is only there for viewing. I would like (need) it part of the actual data becuase I use this information else where (VBA, exports to excel, etc...).
How can I define a field that required the hyphen as part of the real data.
I'm posting this in both VBA and Tables because I don't know if the answer is via a mask or code. Either way is fine
I have a data entry form with several values that could be calculated and entered if I knew how. The FAA requires logging and tracking values that result in the following fields: TimeSEL TimeXC TimeNight TimeDay TimeDual TimePIC TimeTotalFlight
My last flight resulted in entering 3.4, 3.4, 0, 3.4, 0, 3.4, 3.4
My question is: is it possible to add some sort of test expression in the TimeXC field which would examine an associated check box (i.e. "Was flight XC?") and if it was checked then would automatically calculate the flight hours (TachStop-TachStart) and enter the value in the TimeXC field?
I want to get access to create amazon shipments of 15kg in weight made up of a variety of products (the shipment goes to amazon)
So I have a products table with all the weights per unit for each SKU in it.
I've just created a simple 'form', where I input the SKUs I want to send to Amazon & the quantity (this updates a temporary table), therefore I end up with this in my temporary table....
SKU QTY XX01 15 YY01 10
...& so on.
I've made a relationship from the SKU of the temp table (the table where I'm inputting my data to), back to the product table (where the weight per unit is held).
ok, what I seek, is that each time I enter a SKU & Quantity via my form, to see some onscreen data which tells me the ongoing sum of all SKU weights I've used. Therefore I guess my question is...what functionality in Access should I be using that allows me to input data & yet also provides me with onscreen real time data based on some 'behind the scenes' calculations? From my limited understanding, a form is to get data into Access, a report is to get data out....but I want to get data into Access & see the result at the same time!
I have a database where I need to record student data, specifically marks and absenteeism. The marks are recorded each term as a running total. I have a final mark which needs to be equal to the 4th term mark.
I also need to record the number of days absent each term with a total at the end of the year.
My problem is that the term 4 mark is a in the previous record and the total days absent needs to be the total of the previous 4 records (term 1 - 4).
I using a create table query and an update query but that was a no go.
i just know some query designing and some amount of VBA for making small event procedures.I want to know how we can use VBA when our queries becomes complex to replace the queries and to extend the functionality.how to use recordsets in a VBA function.
I would like queries to do some calculations for me based on a field. The field in the form is a combo field and the user can choose either 1, 2 or 3. Based on the selection, I would like queries to generate some numbers for me.
This is what I have in mind but its not working.
Code : TEST RESULT: If([tlkpTEST].[RESULTID])=1, ([tlkpTEST].[RESULTID])*2, 100)
I have come across this problem several times. I have sub reports on a report and calculations are done using the data in the sub report. In many instances the subreport is empty. The calculated fields read #error. (otherwise the report runs well and records with data calculate fine) I would like to hide these errors and associated labels when the subreport is empty. Everything I have tried either does nothing (error still appears in text box - but runs ok otherwise) or I get a runtime error since it is trying to access "nothing" in the sub report. How can I catch and therefore react on this empty sub report. (or subform too) Thanks Lisa
I have made a form based on related tables. it requires me to fill out every field, which I don't want. I didn't make them required. Why does it do that?
I have a database sitting on my server for which individual users login to over the network with their own User name and password. Within my database there are links to data from external sources (SQL based).
My query is, if the database remains open at all times, once the link to the data has been established after keying the SQL database password, how do I stop it from asking each user that logs in to enter the password again each time they dip into the database? (If Possible).
Hi, I'm currently putting together a database for a medical NGO in Cambodia (http://www.medicorps.com/updates/cambodia.html) and am looking for some advice. The simple database is for logging client referral cases by Cambodian doctors to a team of international doctors. I haven't used access in 10 months and despite programming in access for 5 years progress is very slow. At the moment I'm designing the input and search forms. I was thinking that a more logical approach would be to convert the forms to access data pages and put the database online. I haven't used data access pages but from what i know their fairly limited? The goal would be the ability to log/search the data with auto updated pull downlist based on the actual data. Ultimately I want the data compiled and emailed to a email list from withing the website. The trouble is I have no idea how to do it.
I have a form with a subform in a navigation menu. Something like:
Navigation Form NavigationSubform ParentForm (header data and some unbound calculation fields) Subform (Multiple lines tied to query)
I have some fields in the ParentForm (i.e PF1, PF2) that would effect the values on the Subform (i.e. SF1, SF2). Also, there are some user editable values on the subform that will calculate the remaining fields on the subform (still using data from parentform).
My calculations work fine for the changes made on the subform. However I need to be able to calculate all the children lines on the subform when the form loads or a change is made to certain fields on the parentform. My On_Current event only wants to recalculate the first line.
Parent Form PF1=10 PF2=3 Subform QTY ADJ SF1 SF2 Line 1 5 .05 10.6 112.89 Line 2 8 .14 10.38 105.15 ... Line N SF1=PF1+(PF2/QTY) SF2=SF1*(SF1+ADJ)
So if PF1 or PF2 were changed then all the lines is subform would recalc SF1 and SF2. If changes were made to QTY or ADJ, then that line would recalc SF1 and SF2.
I have a database that I'm building off of a process that is currently done in excel. I want my percentages calculations to match what I get in excel but I'm finding the numbers to be off by as much as .4%. I'm pretty sure they issue has to do with the precision of its calculations but what the best settings are.
My percent numbers are currently set to the field size "Double" with a percent formatting. My currency numbers are set to the format Currency and decimal places on auto.
I have a timesheet database, which has the exact start time and exact end time. I want to ignore this if it is five minutes either side of the half hour, and display the exact half hour, but otherwise want to round it UP to the nearest fifteen minutes.
recently posted a thread about a union query. I have got over that hurdle now but face a new problem which is:
When I have created a right join to bring back data from a table, if there is no data it will leave the fields blank. Is there any way I could bring back the row data of the same table.??