In my database I have 1 table - (tbl_RTILog)
I have 1 form that enters the data into this table - (frm_Logger)
I then have a separate form that would update the checkbox in the table - (frm_RTIRev).
My table fields are:
ID - Autonumber
Acc Number - number
MPRN - number
Time Raised - time
Sweep Time - time
Advisor - text
Credit - currency
PayID - text
Reviewer - text
Completed? yes/no
I have a recordset as below in the record source, SELECT tbl_RTILog.[Account Number], tbl_RTILog.MPRN, tbl_RTILog.[Time Raised], tbl_RTILog.[Expected Sweep Time], tbl_RTILog.Advisor, tbl_RTILog.[Credit Amount], tbl_RTILog.[Paypoint ID], tbl_RTILog.[Completed?], tbl_RTILog.ID FROM tbl_RTILog WHERE (((tbl_RTILog.[Completed?])=False)) GROUP BY tbl_RTILog.[Account Number], tbl_RTILog.MPRN, tbl_RTILog.[Time Raised], tbl_RTILog.[Expected Sweep Time], tbl_RTILog.Advisor, tbl_RTILog.[Credit Amount], tbl_RTILog.[Paypoint ID], tbl_RTILog.[Completed?], tbl_RTILog.ID ORDER BY tbl_RTILog.[Time Raised] DESC;
This is filtering the data to only show records where the checkbox returns 'False'.
I have tried changing the recordset type from 'Dynaset' to 'Dynaset (inconsistent updates) and this has made no difference.
All I want to do is for the second form to load (frm_RTIRev) and display all incomplete reviews and then be able to be marked as completed but the 'recordset is no updateable'
Thanks in advance
I have managed to answer my own question in some weird and wonderful unexplainable way.
I recreated the Query and this allowed me to edit the data.
No answer for this apart from that when I remade it it worked straight away.
Related
Pic hereI am new to MS Access. I have a customer table with creationdate field as well as submissiondate. The submissiondate was calculated via a query since it carries multiple conditions. I created a form from the customer table where I am able to input the creationdate field and I managed to show the submissiondate (from the query) via Dlookup but the date is not recorded in the customer table. How can I record the submissiondate value from the query in the customer table without having to do an update query every time I add a new customer? I did an update query but it updates all records every time it runs, and we have more than 50K customers. Any help is appreciated.
this is the query in Access that gets the result for me.
SELECT HardDeadlineCalculationQ1.ID, HardDeadlineCalculationQ1.R AS ReferralDate, HardDeadlineCalculationQ1.[Source of Referral], HardDeadlineCalculationQ1.HD1, HardDeadlineCalculationQ1.wdhd1, HardDeadlineCalculationQ1.hd2, HardDeadlineCalculationQ1.wdhd2, HolidaysT.holidaydates, Switch([HardDeadlineCalculationQ1].hd2=holidayst.holidaydates,"Yes") AS isholiday, IIf(isholiday="Yes",([HardDeadlineCalculationQ1.hd2]-1),[HardDeadlineCalculationQ1].hd2) AS hd3, WeekdayName(Weekday(hd3)) AS wdhd3, Switch(WeekdayName(Weekday(hd3))="Monday",(hd3),WeekdayName(Weekday(hd3))="Tuesday",(hd3),WeekdayName(Weekday(hd3))="Wednesday",(hd3),WeekdayName(Weekday(hd3))="Thursday",(hd3),WeekdayName(Weekday(hd3))="Friday",(hd3),WeekdayName(Weekday(hd3))="Sunday",(hd3-2)) AS hd4, WeekdayName(Weekday(hd4)) AS wdhd4
FROM HardDeadlineCalculationQ1 LEFT JOIN HolidaysT ON HardDeadlineCalculationQ1.hd2 = HolidaysT.holidaydates;
regards,
"The submissiondate was calculated via a query since it carries multiple conditions"
By this, i presume you mean that the submission date is a calculated field(as its control source)
Do the following
Copy the calculation, i.e formula and put in vba code, under the after update event of every field that is a variable in the expression.
e.g submissiondate= place the formular here
Then on the form remove the calculation , i.e formula from the control source of the form control and make a field in the table the control source, e.g submissiondate.
I have an issue writing a query in MS Access that would pull information from two tables.
Quick description:
Employees start the job and click the button in Excel macro. The macro saves the date and a comment that the employee provides (not required). Next, the macro pushes the information into a table in Access database which gathers all 'check-ins' of all employees. There's a possibility for a person to check-in twice by accident. This is an example how the table would look like after two work days, in a company with three employees:
check-in table example
Similarly, the macro lets a user to check-out, also with optional comment:
check-out table example
What I need is a query that would consolidate two of these tables and show check-in/check-out of employees for a previous day, together with provided comment. So the result of the query would look like this:
outcome of a table for previous day
Column order is absolutely irrelevant here
SELECT min(checkin.[check-in time]), max(checkout.[check-out time]), checkin.[comment] AS [check-in comment], checkout.[comment] AS [check-out comment]
FROM checkin
RIGHT JOIN chekout ON checkin.analyst = checkout.analyst
WHERE checkin[check-in time] = Date()-3;
Bad thing is, MS Access throws:
Syntax error in JOIN operation
Could anyone help me out and advise how should I proceed? Unfortunately I have no control how the system was implemented (Macro in Excel connected with Access) and sadly I have not much experience in MS Access.
EDIT:
Thank you very much #Erik, much appreciated. It helped a lot and I'll be more diligent next time when it comes to typos. The new problem presented itself however. It is possible for a person to check-in, without checking-out and vice versa. Lets say there's another row in the first table -> Meg015 checked in at 7:20 on 08.06.2018 but forgot to check out:
see an example
I would like MS Access to present this information accordingly (without forgotten check-out time):
How it should look like
Since there's no Full Outer Join in MS Access, I was thinking about following UNION/LEFT and RIGHT JOINs:
SELECT checkin.analyst, min(checkin.[check-in time]), max(checkout.[check-out time]), checkin.comment, checkout.comment
FROM checkin RIGHT JOIN checkout ON (checkin.analyst = checkout.analyst OR checkout.analyst = NULL OR checkin.analyst = NULL)
WHERE (format(checkin.[check-in time], "Short Date") = format(checkout.[check-out time], "Short Date") OR checkout.[check-out time] = NULL) AND format(checkin.[check-in time], "Short Date") = date()-3
GROUP BY checkin.analyst, checkin.comment, checkout.comment
UNION
SELECT checkout.analyst, min(checkin.[check-in time]), max(checkout.[check-out time]), checkin.comment, checkout.comment
FROM checkin LEFT JOIN checkout ON (checkin.analyst = checkout.analyst OR checkin.analyst = NULL OR checkout.analyst = NULL)
WHERE (format(checkin.[check-in time], "Short Date") = format(checkout.[check-out time], "Short Date") OR checkin.[check-in time] = NULL) AND format(checkin.[check-in time], "Short Date") = date()-3
GROUP BY checkout.analyst, checkin.comment, checkout.comment;
Sadly, Meg's check-in details are not visible in a result of the query above. Any idea how to resolve this issue?
You're missing a dot, have misspelt checkout in your join, and are using aggregates without grouping by the other columns.
Also, you're testing if a date is equal to a date with time, which will pretty much always be false.
Anyway, this is how your query should look like:
SELECT checkout.analyst, min(checkin.[check-in time]), max(checkout.[check-out time]), checkin.[comment] AS [check-in comment], checkout.[comment] AS [check-out comment]
FROM checkin
RIGHT JOIN checkout ON checkin.analyst = checkout.analyst
WHERE DATEDIFF('d',checkin.[check-in time], Date()) = 3
GROUP BY checkout.analyst, checkout.[comment], checkin.[comment]
(Do note that questions with this many errors can get closed as too broad).
I have an MS-Access DB that pulls information in from an Excel file with 6 worksheets, so I get 6 tables. I created 7 queries, all of which make tables from the excel data, 6 of those 7 do a count of an item ie:
SELECT DISTINCT DISPLAYNAME, COUNT(DISPLAYNAME)
FROM [TXFR REC]
GROUP BY DISPLAYNAME
The 7th query pulls those 6 tables together into a sort of report table by using left joins onto one of the tables, where the connection to all the others is a DISPLAYNAME.
I have created a Form with 4 buttons and two date boxes, a start date and an end date. What I want to do is the following:
Choose Start Date
Choose End Date
Press Button that runs the 7 queries in the order I specified by invoking the date range from steps 1 and 2 ** THIS IS WHERE I AM STUCK: I do not know how to force this date range on the queries **
Run the report
Export the report
Close the form
The date boxes are set to General Date and the method used for them is GetDates so you just click in the box and the calendar pops up and you choose your date.
I did see this post here but am not following to well:
Date Range Form
Here is the text from a test query as suggested by a user and in the format suggested by the answering person:
SELECT [NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME, Count([NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME) AS CountOfPHYSICIANDISPLAYNAME INTO NO_ADMIT_DX_COUNT
FROM [NO ADMITTING DX (HEALTH ISSUE)]
WHERE ((([NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME) Is Not Null) And (([NO ADMITTING DX (HEALTH ISSUE)].AdmitDtm) Between Forms!PRINT_REPORT![START DATE] And FORMS!PRINT_REPORT![END DATE]))
GROUP BY [NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME;
** This query now works properly **
Thank you for all the help.
For your query, use something like this.
SELECT DISPLAYNAME, COUNT(DISPLAYNAME)
FROM [TXFR REC]
WHERE [TXFR REC].yourDate BETWEEN [Forms]![yourFormName]![yourStartDate]
AND [Forms]![yourFormName]![yourEndDateField]
GROUP BY DISPLAYNAME
All of your queries that you want to rely on a date range should have these parameters. The advantage to doing it this way is that you can give your two date fields on your form a datePicker. It would still work the same if you did something like this:
SELECT DISPLAYNAME, COUNT(DISPLAYNAME)
FROM [TXFR REC]
WHERE [TXFR REC].yourDate BETWEEN [Please Enter a Start Date]
AND [Please Enter an Ending Date]
GROUP BY DISPLAYNAME
It's all preference though. Just throw a button on there and go to Misc in the wizard and choose run query if you want.
Edit your queries to rely on the value of the form in the where clause:
[Forms]![form's name]![form's control]
Here's a Screenshot example
This will make your queries only work with the form, however. You might consider copying your queries and renaming and editing the copies to reflect its limitation.
As the title says, I'm looking for a way to calculate the percentage of completed tasks a person has. Data is structured so that each individual has can have many tasks, and each task can have many sub-tasks, as described below:
Employees
(pk)(AutoNumber)employee_id
(Text)FirstName
(Text)LastName
Tasks
(pk)(AutoNumber)task_id
(fk)(Number)employee_id
(Memo)Description
(Yes/No)Completed
Sub-Tasks
(pk)(AutoNumber)subtask_id
(fk)(Number)task_id
(Memo)Description
(Yes/No)Completed
I've been trying to make a report (named "Task Completion Rates") that lists all employees, the number of completed tasks they have, the total number of tasks they have, and their completion rate as a percentage. At the moment, I have the following two queries:
SELECT Count(employee_id) FROM [Tasks] AS TotalTasks WHERE [Tasks].employee_id =
Reports![Task Completion Rates]!txt_employeeID
SELECT Count(employee_id) FROM [Tasks] AS CompletedTasks WHERE [Tasks].employee_id = Reports![Task Completion Rates]!txt_employeeID AND [Tasks].Completed = 1
Are both of those necessary, or is there a way to get both counts from one query? Also, how would I go about using those totals in the report? The report's Record Source is set to the Employees table so that it can list them all. I've got text boxes ready to go for each total, but I'm having problems using the expression builder in the source for each text box to actually display the results of the queries. I set the source for one of the text boxes to =[qry_TotalTasksPerEmployee]![TotalTasks] (via expression builder) but it keeps prompting me to enter a value for [qry_TotalTasksPerEmployee]. Any ideas on how get this working?
Try taking the mean of your completed value. For example:
SELECT employee_id, -avg(Completed) FROM [Tasks] GROUP BY employee_id
The - before avg is because true is stored as -1, as pointed out by #Neil.
I'm not sure what you mean about the report - it should be easy to place query results in a report.
I'm not really into msaccess reports but since completed seems to be either a 0 or a 1 you should work towards the following query
-Edit turns out it's either 1 or -1 for bools so can't do a sum(completed) but need an IIF()
Select employee_id, count(*), sum(IIF(completed,1,0)), sum(IIF(completed,1,0))*100/count(*) as rate
From employees
Left join tasks
On tasks.employee_id = employees.employee_id
Group by employee_id
Note that this does create a division by zero problem for employees without tasks. You will have to deceide how to deal withbthose (exclude, show as 0% or ...)
MS Access Scenario:
I am using a form (we'll call it the select_contract form) and a subform (we'll call it the employee_allocations_by_contract subform).
The select_contract form:
Is unbound.
Contains a combobox that allows the user to select a contract id.
The employee_allocations_by_contract subform:
Is a continuous form.
Is bound to a table (which I'll call the hours_allocation table) that contains the number of hours that each employee is allocated to each contract.
Binds only one field, the employee_id field, to the hours_allocation table. The row source for this field is a query that returns the ids of employees that have hours allocated to the contract that the user has selected in the select_contract form.
Contains twelve other, unbound fields, one for each month of the year. These fields are intended to display the number of hours allocated to the employee listed in the employee_id field for each month of the year.
The Problem: In order to display the number of hours by month that are allocated to each employee listed on the employee_allocations_by_contract subform, the queries for each month field need access to the employee_id field of the row on which they appear. I haven't been able to figure out how to reference this field. Because the employee_allocations_by_contract subform is a continuous form, a reference to the the employee_id field name appears to reference each row on the form.
I have searched several forums and have found related continuous form issues, but nothing that clearly addresses this problem. Any thoughts?
Well, you could build a sub-query for each of the month columns you need that total for.
Something like:
Select id, employee_ID, bla, bla, bla,
(select sum(hours) where month = 1 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month1,
(select sum(hours) where month = 2 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month2,
(select sum(hours) where month = 3 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month3
etc. for each column needed
from ehours
Note I used month and year as columns and you likely have to use month([SomeDate]) = 2 and year([SomeDate]) = 2010, but you get the idea.
Also, while you can't address each row and stuff a value into that un-bound text box, you CAN in fact bind the text box to a function that returns the value/expression you need.
txtBoxMonth1 txtboxMonth2 etc.
=MyMonth(1,[employee_id]) =MyMonth(2,[Employee_id])
And, then in the form, you have a public function called
Public Function MyMonth(intMonth as interger, lngEMPID as long) as long
' code here to get total based on employee id and month
End Funciton
So, you can bind a function to those text boxes, and the current row emp ID can thus drive what each text box displays. Just remember that this function should have all of the data pre-processed, and you don't want to have to re-run and re-load the data for each function call as that will be FAR too slow. However, I have used this approach to much success. So, each row of the form only has one real column (empID), the rest of the columns are derived from text boxes bound to the public function as per above with the month being passed along with the emp id to return the value for that column.
So, above is two possible approaches I used with success.
An unbound control on a continuous form can only refer to the record that has the focus. There fore, if data is entered into an unbound control, you will see the same data for every record in the continuous form.
You cannot reference controls "individually" ("at the line level") in a MS Access continuous form.
Your only solution here is to bound these controls to an underlying recordset\recordsource where corresponding fields hold the values to be displayed.
For example, if you want to display a time period as the difference between a "date in" and a "date out", your recordset\recorsource could be something like:
select id_person,dateIn,dateOut,dateDiff(xx,dateOut, dateIn) as timeIn from ...
Then your time calculation control has to be bound to the 'timeIn' field of the recordset.
(*) please check the dateDiff arguments. I do not have any help available here ..