473,320 Members | 1,707 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,320 software developers and data experts.

DateDiff - User defined Interval

Hello,
I have a query with a DateDiff function in it. I was wondering if it is possible to make the "interval" a user defined field. I have already created a form with an unbound value box with two columns. The first being "d", "ww", "m", and "yyyy". The second column being Day, Week, Month, and Year. In the Quays SQL it tried DateDiff(((Forms)!(Form_Name)!(Column1_Name)), Date1, Date2). but I get a missing operator error. Any help anyone could offer would be very much appreciated.

- DanYork
Oct 1 '07 #1
5 1925
FishVal
2,653 Expert 2GB
Hi, Dan.

Sure this is possible. Specific column value may be retrieved with Combobox.Column property.
e.g. for the first column (numeration starts from 0)
Expand|Select|Wrap|Line Numbers
  1. DateDiff(Forms!Form_Name!Comobox_Name.Column(0), Date1, Date2)
  2.  
Oct 1 '07 #2
Hi, Dan.

Sure this is possible. Specific column value may be retrieved with Combobox.Column property.
e.g. for the first column (numeration starts from 0)
Expand|Select|Wrap|Line Numbers
  1. DateDiff(Forms!Form_Name!Comobox_Name.Column(0), Date1, Date2)
  2.  
Thank you for your quick responce. I am still getting a Syntax error (missing operater). Outside of of horrible naming conventions (don't you love working in databases you didn't design...) can you see where the error is in my query? Thank you again for your help.

Code Start:
SELECT Investments.Investment_Name, Round(Avg(DateDiff(Forms!Criteria for Average Time to Close an Action Item!List9.Column(0), Reviews.Review_Date, ActionItems.Completion_Date)), 2) AS ["Average # of Weeks to Close"], Investments.Investment_ID
FROM (Investments INNER JOIN Reviews ON Investments.Investment_ID = Reviews.Investment_ID) LEFT JOIN ActionItems ON Reviews.Review_ID = ActionItems.Review_ID
WHERE (((ActionItems.Completion_Date) Is Not Null And (ActionItems.Completion_Date) Between [Enter Start Date (mm/dd/yy)] And [Enter End Date (mm/dd/yy)]))
GROUP BY Investments.Investment_Name, Investments.Investment_ID
ORDER BY Investments.Investment_Name;
Code End

Sincerely,
danyork
Oct 2 '07 #3
FishVal
2,653 Expert 2GB
Thank you for your quick responce. I am still getting a Syntax error (missing operater). Outside of of horrible naming conventions (don't you love working in databases you didn't design...) can you see where the error is in my query? Thank you again for your help.

Code Start:
SELECT Investments.Investment_Name, Round(Avg(DateDiff(Forms!Criteria for Average Time to Close an Action Item!List9.Column(0), Reviews.Review_Date, ActionItems.Completion_Date)), 2) AS ["Average # of Weeks to Close"], Investments.Investment_ID
FROM (Investments INNER JOIN Reviews ON Investments.Investment_ID = Reviews.Investment_ID) LEFT JOIN ActionItems ON Reviews.Review_ID = ActionItems.Review_ID
WHERE (((ActionItems.Completion_Date) Is Not Null And (ActionItems.Completion_Date) Between [Enter Start Date (mm/dd/yy)] And [Enter End Date (mm/dd/yy)]))
GROUP BY Investments.Investment_Name, Investments.Investment_ID
ORDER BY Investments.Investment_Name;
Code End

Sincerely,
danyork
Hi, danyork.

The following expression is problematic.
Expand|Select|Wrap|Line Numbers
  1. Forms!Criteria for Average Time to Close an Action Item!List9.Column(0)
Names breaking Access naming rules (containing forbidden characters, reserved words etc) has to be enclosed in square brackets. I can only guess what does mean "Item" in the expression, whether it part of the form name or Item property. Anyway I will assume it to be part of the form name, bkz Form does not have Item property. Well Form has default Controls property that does have Item property, but the Item property doesn't return collection so couldn't be followed by "!" operator. So "Criteria for Average Time to Close an Action Item" is the form name and the expression should look like:
Expand|Select|Wrap|Line Numbers
  1. Forms![Criteria for Average Time to Close an Action Item]!List9.Column(0)
P.S. Oh, ye. I hate to work with databases I've not designed. But who loves it?
Oct 2 '07 #4
Hi, danyork.

The following expression is problematic.
Expand|Select|Wrap|Line Numbers
  1. Forms!Criteria for Average Time to Close an Action Item!List9.Column(0)
Names breaking Access naming rules (containing forbidden characters, reserved words etc) has to be enclosed in square brackets. I can only guess what does mean "Item" in the expression, whether it part of the form name or Item property. Anyway I will assume it to be part of the form name, bkz Form does not have Item property. Well Form has default Controls property that does have Item property, but the Item property doesn't return collection so couldn't be followed by "!" operator. So "Criteria for Average Time to Close an Action Item" is the form name and the expression should look like:
Expand|Select|Wrap|Line Numbers
  1. Forms![Criteria for Average Time to Close an Action Item]!List9.Column(0)
P.S. Oh, ye. I hate to work with databases I've not designed. But who loves it?
I'm so close but yet so far.. with your advice I have moved past the Syntax error and am now getting a "Undefined Faction 'Forms![Criteria for Average Time to Close an Action Item]!List9.Column' in expression" error. It doesn't look to me like it is picking up the column number correctly. FYI I have changed the list box to a combo box as you suggested. Thank you again for your continued help. I've been toying with this darn thing on and off for two days now!!
Sincerely,
danyork
Oct 2 '07 #5
FishVal
2,653 Expert 2GB
I'm so close but yet so far.. with your advice I have moved past the Syntax error and am now getting a "Undefined Faction 'Forms![Criteria for Average Time to Close an Action Item]!List9.Column' in expression" error. It doesn't look to me like it is picking up the column number correctly. FYI I have changed the list box to a combo box as you suggested. Thank you again for your continued help. I've been toying with this darn thing on and off for two days now!!
Sincerely,
danyork
Hm. Really don't work.
Well this should work anyway.
  • put the following function to any public module
    Expand|Select|Wrap|Line Numbers
    1. Public Function GetIntervalUnit() As String
    2.     On Error Resume Next
    3.     GetIntervalUnit = Forms![Criteria for Average Time to Close an Action Item]!List9.Column(0)
    4. End Function
    5.  
  • now change your query to
    Expand|Select|Wrap|Line Numbers
    1. SELECT Investments.Investment_Name, Round(Avg(DateDiff(GetIntervalUnit(), Reviews.Review_Date, ActionItems.Completion_Date)), 2) AS ["Average # of Weeks to Close"], Investments.Investment_ID
    2. FROM (Investments INNER JOIN Reviews ON Investments.Investment_ID = Reviews.Investment_ID) LEFT JOIN ActionItems ON Reviews.Review_ID = ActionItems.Review_ID
    3. WHERE (((ActionItems.Completion_Date) Is Not Null And (ActionItems.Completion_Date) Between [Enter Start Date (mm/dd/yy)] And [Enter End Date (mm/dd/yy)]))
    4. GROUP BY Investments.Investment_Name, Investments.Investment_ID
    5. ORDER BY Investments.Investment_Name;
    6.  

P.S. Actually I didn't recommend you to change Listbox to Combobox control. You can stay with either. The code is applicable to both'em.
Oct 2 '07 #6

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

Similar topics

6
by: Lofty | last post by:
Hi all. I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!) I need to work out the difference in days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
3
by: T23Ij9 | last post by:
Hi. I have 3 seperate date fields. InitialDate InspDate ReportDate I am trying to setup several unbound Text boxes in a form that will give me days elapsed between these dates. These text...
2
by: Contro | last post by:
Hi there! I hope you can help me! I have the following code: SELECT COUNT(Applications.) AS TOTAL FROM Applications WHERE DateDiff('d',,Date()) <6 AND = "Certificate"; Which returns the...
5
by: sr | last post by:
Anyone know of a better way to simulate a datediff for C#, i.e., without referencing the VB.NET runtime? Only added the functionality that was needed for me so it is not the full implementation...
9
by: laurenq uantrell | last post by:
I've gotten sort of fed up with dealing with regional date settings on the client side and am considering the following scheme - just wondering if anyone has a negative view of it or not: ...
5
by: BUmed | last post by:
I want to set up a Query to show the diffence between 2 dates and the output to be in months and weeks. So the child is 15months and 2weeks (15/2). I have been try to modify DateDiff Age:...
4
by: misaw | last post by:
for portability in SQL query ie a query written for one DB runs fine for other i try to standardize our SQL queries as far as i can.... For finding the date difference we have: DATEDIFF...
7
by: JenM | last post by:
Hi. I am a novice user. I am using the datediff function in a query. I am trying to calculate the number of week days between two dates. When I use "m" as the interval, the number of weeks is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.