Access query using calculation - ms-access

I'm trying to make a query using a calculation with Date().
I have a field named [Currentordue] and a field named [duedate]. What I'm trying to accomplish is making a query to limit the results by "if [currentordue] equals "due" or if [duedate] minus today's date is less than 30 days."
I've tried a few different ways but always seem to end with either an error or with no results showing (which would be an error as well since I know there are fields that are due).
Any and all help would be appreciated.

Here is a way to use two different date conditions:
SELECT Table1.Currentordue, Table1.duedate, DateDiff("d",[duedate],Date()) AS Expr1
FROM Table1
WHERE (((DateDiff("d",[duedate],Date()))<30)) OR (((Table1.Currentordue)=[duedate]));

Related

How to use DateDiff in calculated field in access

I am trying to get "No of days late" in a particular table in MS access. I am trying to use calculated data type.
I have [ActualReturnDate] and [ReturnDate] in the same table (both are Date/Time) and I want to save difference between two columns in a calculated field.
I am using following expression:
DateDiff("d", [ActualReturnDate] , [ReturnDate] )
But no matter what i do I get error saying "The expression X cannot be used in a calculated column."
So does that mean I cannot use DateDiff in Calculated field? If not how should I do it?
You indeed can't do this in a calculated field.
Use a query instead, add a column and do the calculation in that column.
You can just add and substract dates.
Just use [ActualReturnDate] - [ReturnDate] as the expression to calculate the difference. If both fields are defined as date/time, the result should be the same, only include the time part as decimal.
If you want only whole days, you can wrap the result in Int()

Mysql select part of field and return full value

Good day all,
I have a field called mCodes which has the exact length (7) throughout the table but with different values i.e. a few records with 5036100, 5036102, 5036103, 7010100, 7010101 etc.
I am using a select statement to first search for the first 4 characters i.e 5036 which will return all the records with 5036 just fine
I now need to return the actual full value of the records 5036100 etc. without recreating another sql statement. My statement I am using is as follow -
SELECT LEFT(MCODE, 4), MAKE, MODEL, NEWPRICE23 FROM mautogd1015 WHERE LEFT(MCODE, 4) = '5036'
I have racked my brain over this for a few hours now, any help will be appreciated.
Try something like this.
SELECT MCODE, MAKE, MODEL, NEWPRICE23 FROM mautogd1015 WHERE LEFT(MCODE, 4) = '5036'

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.

Datediff fuction in Access produce answer of 1 instead of 0 for same day

I am trying to get a total number of days hired using the DateDiff function is access.
I currently use:
=DateDiff("d",[hired_from],[hired_to])
To get the difference between two dates, however if the two dates selected are the same it will produce an output of 0, I would like it to produce an output of 1 when the two dates selected are the same, thanks.
It doesn't make much sense as the difference between two identical values always will be zero.
So you probably mean:
=DateDiff("d",DateAdd("d",-1,[hired_from]),[hired_to])
or just add one to the count:
=DateDiff("d",[hired_from],[hired_to])+1
I ended up making this work by using an if statement as shown:
==IIf(DateDiff("d",[hired_from],[hired_to])=0,1,DateDiff("d",[hired_from],[hired_to]))
to get the difference of two dates (which is only a format for an integer value), you have only to subtract the two dates and make sure that the result format is an integer.
Variable = [hired_to]-[hired_from]

Odd results in MS Access Query using a DSUM function and parameters

I've just started using MS Access this month and I have a very odd bug. I'm trying to create a query that searches for records in a table that have a maxBenefit (a dsum from a different table's field, with a one to many relationship) within a certain range. I'm using the DSUM function to get the maxBenefit because the table has a dailyBenefits field that need to be added together.
Here is my function:
maxBenefitOfQuote: Nz(DSum("[wholeYearBenefit]","tblDisabilityQuoteDailyBenefits",
"[quoteID] = " & [tblDisabilityQuotes].[ID]))
I know the function works because it produces the correct values. The query also takes in two parameters from a form to create a range for maxBenefits.
I limit the results with this criteria:
>=[Forms]![frmDisabilityFindSimilarQuotes]![minBenefitTotal] And
<=[Forms]![frmDisabilityFindSimilarQuotes]![maxBenefitTotal]
The problem is I get very odd results from the query with maxBenefits outside the range or not returning records with maxBenefits inside the range. If I set the minBenefitTotal to 0 and the max BenefitTotal to 100000000 I get no records returned from the query. If I set the minBenefitTotal to 0 and the maxBenefitTotal to 999999999 I get all the proper records.
Any ideas why this is happening? Thanks in advanced.
First,
Try wrapping both of your inputs in a call to CCur:
>=CCur([Forms]![frmDisabilityFindSimilarQuotes]![minBenefitTotal]) And
<=CCur([Forms]![frmDisabilityFindSimilarQuotes]![maxBenefitTotal])
Next,
If you omit the actual form inputs, and hard-code numbers into the criteria, does it work?
For Example: (>= 0 and <= 100000000)
If that worked... It feels like a string -> number conversion issue. Make sure all string input is actually a number (via CCur()) before sending it into the query.