I did a query in access that calculates a date, when I enter the date in a form I get the result in the query but not able to save it to the table - ms-access

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.

Related

populating field data by Dlookup in access

I'm trying to populate data from a query (SUMA PALETS) that counts the records from a field (its related table is called "LOTES PRODUCTOS") to a field in a subform (PEDIDOS PRODUCTOS). Both, query (and its related table) and subform (and its related table) have a common field with the same value. This field is called "PRODUCTOPEDIDO" in SUMA PALETS query and in LOTES PRODUCTOS table and it is called "IdPEDIDOSPRODUCTOS" in the subform.
I'm using the next formula in the control source of the subform field (it's called "QUEDAN"):
=DLookUp("[CountofIdPEDIDOSPRODUCTOS]";"[SUMA PALETS]";"[PRODUCTOPEDIDO] = " & Forms![PEDIDOS PRODUCTOS]![IdPEDIDOSPRODUCTOS])
Where:
SUMA PALETS: It's the query name
PRODUCTOPEDIDO: table field I want to count
CountofidPEDIDOSPRODUCTOS: it's the query field that counts PRODUCTOPEDIDO field in the query
PEDIDOS PRODUCTOS: subform name
IDPEDIDOSPRODUCTOS: subform field name with the same value as - PRODUCTOPEDIDO in query.
But I get #Name? error in the subform field. I don't know where is the problem. Could It be because the field's name is the same in another tables?
I would like that QUEDAN field was updated instantly when I add records in LOTES PRODUCTOS field (by introducing data in a subform). I don't know If It`s the right approach or could It be better option If I write a query to get count values directly in QUEDAN field (I don't know much about queries in SQL).
Thanks in advance
Should be:
=DLookUp("[CountofIdPEDIDOSPRODUCTOS]";"[SUMA PALETS]";"[PRODUCTOPEDIDO] = " & Forms![ParentFormName]![PEDIDOS PRODUCTOS]![IdPEDIDOSPRODUCTOS])
You need to refer to the parent form before the subform.

MS Access 2010 input date once for multiple sub reports

I've been banging my head against this for weeks, have Googled every permutation of the question that i can think of, and have still got nowhere, so any help would be really appreciated.
WHAT I NEED:
I need to generate a report, which pulls summaries of our referrals from the database. I have two reports which use the following queries as their Record Source:
SELECT referrals.origin_country, Count(*) AS ['number']
FROM referrals
WHERE (((referrals.referral_date) Between [Enter Start Date] And [Enter End Date:]))
GROUP BY referrals.origin_country;
And
SELECT referrals.first_language, Count(*) AS ['number']
FROM referrals
WHERE (((referrals.referral_date) Between [Enter Start Date:] And [Enter End Date:]))
GROUP BY referrals.first_language;
The queries are nearly identical, and the date range is the same for each one.
The issues is that when I generate a report which uses these two reports as subreports, I then have to enter the date range for the subreports twice (once for the Country of Origin Subreport, and once for the First Language Subreport.
My Access skills are not as advanced as I would like, and I'm wondering if anybody can tell me how to ensure that the user only has to enter the date range once?
I've tried
Using VBA to create a variable onLoad, but then couldn't work out how to use this variable in the Record Source Query...
Using VBA to create a function which sets a variable onLoad, but then couldn't work out how to use the function in my Record Source query...
Any suggestions would be greatly appreciated!
Create a form with fields for the start and end date, and a button on it, which launches your main form. Use the 'Embedded Macro' Wizard to open the chosen Report On Click.
Then, use [Forms]![FORM NAME]![FIELD NAME] in the query to access the date, for example:
SELECT referrals.origin_country, Count(*) AS ['number']
FROM referrals
WHERE (((referrals.referral_date) Between [Forms]![EAL Referral Search Form]![dat_termly_report_start] And [Forms]![EAL Referral Search Form]![dat_termly_report_end]))
GROUP BY referrals.origin_country;

MS Access - Use result from query to calculate field value

I'm trying to pull some data from a query in my database into a calculated field in a table. I have dates entered for some jobs I'm recording (DateCallOpened, DateQuoteSent, DateQuoteReceived), as well as WorkType for each job to track the type of work done. I've used calculated fields to find the time it took for each record between those dates. I've also used qryTimings to find the average length of time for the WorkType.
I'd like to build fields that showed the ProjectedQuoteSent, and use the data from my query to calculate the date I can expect the quote to be sent, but I just can't figure out how to pull that data out of the query. I was hoping it would be something as simple as:
=[DateCallOpened]+[qryTimings]:[Avg Of TimeToSendQuote]
You can use a DLookup() function to grab your value from your query. So your formula would be something like:
=[DateCallOpened]+DLookup("Avg Of TimeToSendQuote", "qryTimings", _
"[WorkType]=" & [Forms]![frmMyForm]![txtWorkTypeInput])
See this for more info.

Microsoft Access 2010 filtering data based on tempvar

i have a web database and im trying to filter a datasheet, based on the contents of a tempvar. Im trying to use the record source property of the datasheet to do this.
I need to do this because, every employee that logs in should only be able to see a given subset of data in the products table. In the employee table, i have an extra column with a string value which is the data that particular employee should see.
I have a login form that on clicking login, adds this string to the tempvars collection.I can see the tempvar has been added in the immediate window as shown below:
?tempvars!tmpgrpdsc -> "IAMS"
i use the query builder option to complete the record source property as shown below.
The problem is, nothing is returned !
But when i enter the string "IAMS", i get records returned.
However, i have done this with another datasheet and it has worked, the tempvar here held a number ! See below:
What am i missing or is there a better way to filter records based on the login. Thanks
What you showed should work.
However, have you tried to change the criteria to ="""" & [Tempvars]![tmpGrdsc] & """"
Also, to make sure that your tempvar is actually containing the data during the query, you could show it as a field, just to check exactly what data is being returned during the query:
SELECT Orders.*,
[Tempvars]![tmpGrdsc] AS TmpGrdsc
FROM Orders

How to Reference Individual Form Elements in a MS Access Continuous Form

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 ..