473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Date Expression Question

MCMike
11
Good Afternoon,

I am having difficulty writing an expression for a query.

I would like Overdue: to return "Overdue" if the date in [Application-Next] is between current date and current date minus one month, (for example, return any dates between 30 May 2017 through today, 30 June 2017).


Something like the below:

Expand|Select|Wrap|Line Numbers
  1.   Overdue: IIf([Application-Last]Between Date() And DateAdd("m",-1,Date()), "Overdue")  
No matter what I try I can't get the syntax right.

Thank you so much for your support.

MCMike
Jun 30 '17 #1
18 1334
MCMike
11
I understand that I mistakenly typed Application-Last in the expression example. I used Application-Next when trying to write the expression in the query and still received syntax errors. Thanks.
Jun 30 '17 #2
BikeToWork
124 100+
Make sure that there is a space between ] and Between. Also, try switching the date parameters around so that DateAdd("m", -1, Date()) comes before Date() in the expression. Are you sure that [Application-Last] is of date datatype?
Jun 30 '17 #3
NeoPa
32,556 Expert Mod 16PB
You give no indication of what you actually receive. Error message? An unexpected value? Hard to work when information isn't shared.

The only thing I see wrong is the lack of a third parameter. Surely putting the first value as the lower limit makes good sense, as does a space before Between, but I don't see either as problems.

As I say though, we don't know what you're seeing so it's just intelligent guessing really.
Jul 1 '17 #4
PhilOfWalton
1,430 Expert 1GB
I think BikeToWork has hit the nail on the head about Application-Next not being a date.

Try this

Expand|Select|Wrap|Line Numbers
  1. OverDue: IIf(IsDate([Application-Next]),IIf([Application-Next] Between Date() And DateAdd("m",-1,Date()),"Overdue"),"Not a Date")
  2.  
Phil
Jul 1 '17 #5
NeoPa
32,556 Expert Mod 16PB
Hi Phil.

That still leaves only the first two parameters for the IIf(). The OP could be confused by the results when this is not hit and it defaults to FALSE. We don't yet know what the OP considers to be the error. Could be simply that. Also, the field may be of DateTime type yet still contain a Null, which wouldn't be a DateTime per se. No Nz() so not handled if it is. All possibilities. All just guessing without any idea what the actual problem is that's been reported (almost).
Jul 1 '17 #6
MCMike
11
Sorry the delay in response, I have been away. I will deliver the error message in a bit. It was a syntax error but I will let you know exactly where in the expression it occurred and exactly what it said possibly later today but definitely tomorrow. Thank you.
Jul 5 '17 #7
NeoPa
32,556 Expert Mod 16PB
Hi MCMike.

May I suggest that you check the ideas already raised and see if any are pertinent before you give us the error message and details. It may be one of them resolves it. We're not likely to think of saying the same thing again if it does turn out that way so excluding those before posting makes good sense.

Good luck.
Jul 5 '17 #8
MCMike
11
Indeed I will sir. Thank you.
Jul 6 '17 #9
MCMike
11
Ok,

Note: I am in fact working with a date field [Application-Next] from table OPS (confirmed date field in design view)

When I run a query with the original expression:

Expand|Select|Wrap|Line Numbers
  1. Overdue: IIf([Application-Next]Between Date() And DateAdd("m",-1,Date()), "Overdue")  
I receive the following error: The expression you entered contains invalid syntax. You may have entered an operand without an operator.

When I click OK, the initial expression header "Overdue:" gets highlighted black and that's it. No other indications in the expression as to where the error might lie.

Same error occurs when I modify the expression per suggestion from Phil with suggestion from Bike,

Expand|Select|Wrap|Line Numbers
  1. OverDue: IIf(IsDate([Application-Next]),IIf([Application-Next] Between Date() And DateAdd("m",-1,Date()),"Overdue"),"Not a Date")
The expression you entered contains invalid syntax. You may have entered an operand without an operator.

When I click OK, the initial expression header "Overdue:" gets highlighted black and that's it. No other indications in the expression as to where the error might lie.

Do you guys accept zipped database files? It is a small file and I'm certain could be easily analyzed with a small write-up by me.

Thanks,

MCMike
Jul 6 '17 #10
BikeToWork
124 100+
Try a space between the ] and the Between.
Jul 6 '17 #11
NeoPa
32,556 Expert Mod 16PB
Hi MCMike.

Some do. Not all either can or will. I'd be happy to. Make sure any linked tables are replaced (Copy/Paste) with local ones and test for the same problems just before you ZIP it to send.

In your first version, as well as the second IIf() of the second version, you have no third parameter. I just checked this and it shouldn't cause an issue.

@BikeToWork.
Check out the second version he tried. If you try to enter it that way Access corrects it for you automatically.

@MCMike.
That brings up a very good point. You should ensure you never post anything here that is not an exact match of what's in the system. That's not necessarily what you type in, particularly in a situation like this where it is fixed for you automatically. Always copy and paste what's in the database.
Jul 6 '17 #12
MCMike
11
NeoPa,

I will put the tables into the front end and test everything you suggest before zipping/sending. If I still need to, where do I send the zipped file?

Thanks,

MC
Jul 6 '17 #13
NeoPa
32,556 Expert Mod 16PB
You attach it to your next post. This can only be done using the Advanced button.
Jul 6 '17 #14
MCMike
11
Thanks, NeoPa,

I don't think I can from work. Our network strips anything executable or just renders it as a useless text file full of garbage. I will have to put to disk and send from home. I will try but I doubt it will make it to you intact.

It's really a small piece of junk DB that I sort of inherited. My write-up should clear up what I am trying to do. I will send it later this evening or tomorrow afternoon.

MCMike
Jul 6 '17 #15
MCMike
11
I tried BikeToWork's suggestion of "Try a space between the ] and the Between". That worked along with the fact that I had to change some of my dates in [Application-Next] to be within the month minus 1 range because my test copy is over a month old. With those two changes, the expression returned some values of "Overdue" as hoped!

I am going to try using the "Overdue" values in yet one more conditional formatting attempt. If I can't get it I will send the database. But the below expression works:

Expand|Select|Wrap|Line Numbers
  1. Overdue: IIf([Application-Next] Between Date() And DateAdd("m",-1,Date()), "Overdue")
THANKS to ALL!
Jul 6 '17 #16
NeoPa
32,556 Expert Mod 16PB
Hi.

As I pointed out in post #12 it's generally not possible to enter Between immediately after the ] in such a query. Besides, your second attempt from post #10 shows you already tried that and it didn't fix any issue. I suspect therefore, that what you were seeing was a result of some of your data.

Your last comment though, indicates the problem actually changed somewhere between then and now. Originally you were reporting an error message. Now it seems you're treating the earlier absence of expected results as an error (Unless I misinterpret your comments). Two completely different things. You need to be very clear about such things when you're reporting problems on a forum otherwise you'll be sending people off on wild goose chases.

Can you explain at exactly which point the error message disappeared?
Jul 6 '17 #17
MCMike
11
I apologize. I may have inadvertently reported that I tried to put a space after the ] before Between when in fact I had not yet tried it.
Jul 7 '17 #18
NeoPa
32,556 Expert Mod 16PB
It shouldn't make any difference MCMike. What you reported was inaccurate from the very first. Just try to enter it without the space and you'll see, when you look at it again, that the space was added for you. It's not possible to have it without a space in a normal QueryDef.

That's why I made that comment in post #12 about posting the information accurately. Everyone's attention has been on something that is a result of posting what you think you typed in rather than COPYing and PASTing what you have there. Something that isn't there.
Jul 7 '17 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: peterbe | last post by:
I want to match a word against a string such that 'peter' is found in "peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or "hey peterbe," because the word has to stand on its own....
2
by: Aloof | last post by:
Using Access 2000 Windows Server 2003 The following code worked fine until we moved hosting companies StartDate = Request.Form("StartDateMonth") & "/" & Request.Form ("StartDateDay") & "/" &...
2
by: Mary | last post by:
I am trying to develop a query which will determine the average costs using a rolling average of the past 12 months of data. In other words, if I entered the Ship Month of January and the Ship...
7
by: Gerry Abbott | last post by:
Probly belongs to a programmers group, but I want to evaluate the expression If a=b=c=d=e then (if there are all equal) something else something else. Is there an easy way for this in VB?
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
20
by: Larry Woods | last post by:
I'm drawing a blank... What is the regular expression for search a string for NO occurances of a substring? Example: I want to find all lines that do NOT have the substing "image" in them. ...
2
by: zMisc | last post by:
I got a table with the following fields: BirthDay (Date) Reminder (Short integer) I need to select all records where BirthDay - Reminder <= Today to display a reminder. In Access and MS...
6
by: Wayne Wengert | last post by:
I hope this is an appropriate group for this question - if not, let me know where I should take this question. I want a regular expression that will validate a date in the format mm/dd/yyyy. I...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
12
by: stevebread | last post by:
Hi, I am having some difficulty trying to create a regular expression. Consider: <tag1 name="john"/ <br/<tag2 value="adj__tall__"/> <tag1 name="joe"/> <tag1 name="jack"/> <tag2...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.