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

Access query getting #error

4
Hoping someone can help with this! I am receiving a #error when subtracting two dates when one or both of the date fields is blank. I created a function called Workdays which removes weekends & holidays. I am just not sure how to get rid of the #error. Below is the code that I am using.

Wrkdays1: Workdays([startDate),[endDate])

When both the startDate and endDate fields contain dates, it works perfectly....instead of the #error, I need the field to be blank because I need to do additional queries off of this data.

Thanks
Nov 13 '16 #1
5 846
Narender Sagar
189 100+
Hi Mark,
Create new fileds in query with if statement.
Something like :
Expand|Select|Wrap|Line Numbers
  1. EndDt: iif([EndDate] is null,0,[EndDate])
and similarly for StartDate...StartDt
Expand|Select|Wrap|Line Numbers
  1. StartDt: iif([StartDate] is null,0,[StartDate])
then subtract these fields.. and check
Nov 13 '16 #2
jforbes
1,107 Expert 1GB
Would you post your Workdays() Function?
Nov 13 '16 #3
Mark27
4
Hi Narender,
Thank you for responding! I followed your suggestion and had some issues but I finally figured it out. My issue was if I had a startdt but no enddt. I would get an answer like 30378. This makes sense because it is subtracting a date from nothing. My fix was I created another field and set anything to 0 that was great than 1,000.

Really appreciated your help on this!
Mark
Nov 13 '16 #4
Mark27
4
Hi jforbes,

I am using the workdays function from the link below that removes weekends & holidays. You can copy the information from the link into two modules one "week days" and one "work days". You will also need to create a table for holidays.

Once that information is loaded in your database, you can query off of a table that has a start date and end date by doing the follwing:

Wrkdays1: Workdays([Startdate],[Enddate])

https://msdn.microsoft.com/en-us/lib...ffice.12).aspx
Nov 13 '16 #5
PhilOfWalton
1,430 Expert 1GB
You may find the following helpful:-
Expand|Select|Wrap|Line Numbers
  1.  
  2. Function EasterDate(Yr As Integer) As Date
  3.  
  4.     Dim Da As Integer
  5.     Da = (((255 - 11 * (Yr Mod 19)) - 21) Mod 30) + 21
  6.     EasterDate = DateSerial(Yr, 3, 1) + Da + (Da > 48) + 6 - ((Yr + Yr \ 4 + _
  7.     Da + (Da > 48) + 1) Mod 7)
  8.  
  9. End Function
  10.  
  11.  
  12. Public Function GoodFriday(Yr As Integer) As Date
  13.  
  14.     GoodFriday = DateAdd("d", -2, EasterDate(Yr))
  15.  
  16. End Function
  17.  
  18. Public Function EasterMonday(Yr As Integer) As Date
  19.  
  20.     EasterMonday = DateAdd("d", 1, EasterDate(Yr))
  21.  
  22. End Function
  23.  
  24. Public Function AscensionDay(Yr As Integer) As Date
  25.  
  26.     AscensionDay = DateAdd("d", 39, EasterDate(Yr))
  27.  
  28. End Function
  29.  
  30. Public Function FirstSpringHoliday(Yr As Integer) As Date
  31.  
  32.     FirstSpringHoliday = DateSerial(Yr, 5, ((7 - Weekday(DateSerial(Yr, 5, 7))) + 2) Mod 7)
  33.     'DateSerial(Year(mydte), Month(mydte), ((7 - Weekday(DateSerial(Year(mydte), Month(mydte), 7))) + 2) mod 7)
  34.  
  35. End Function
  36.  
  37. Public Function LastSpringHoliday(Yr As Integer) As Date
  38.  
  39.     Dim TheDay As Integer
  40.  
  41.     TheDay = Day(DateSerial(Yr, 5, ((7 - Weekday(DateSerial(Yr, 5, 7))) + 2) Mod 7))     ' First Spring bank holiday
  42.  
  43.     TheDay = TheDay + 28
  44.     If TheDay <= 31 Then
  45.         LastSpringHoliday = DateAdd("d", 28, DateSerial(Yr, 5, ((7 - Weekday(DateSerial(Yr, 5, 7))) + 2) Mod 7))
  46.     Else
  47.         LastSpringHoliday = DateAdd("d", 21, DateSerial(Yr, 5, ((7 - Weekday(DateSerial(Yr, 5, 7))) + 2) Mod 7))
  48.     End If
  49.  
  50. End Function
  51.  
  52. Public Function ChristmasDay(Yr As Integer) As Date
  53.  
  54.     ChristmasDay = DateSerial(Yr, 12, 25)
  55.  
  56. End Function
  57.  
  58. Public Function BoxingDay(Yr As Integer) As Date
  59.  
  60.     BoxingDay = DateSerial(Yr, 12, 26)
  61.  
  62. End Function
  63.  
  64. Public Function NewYearsDay(Yr As Integer) As Date
  65.  
  66.     NewYearsDay = DateSerial(Yr, 1, 1)
  67.  
  68. End Function
  69.  
  70. Public Function Scots2January(Yr As Integer) As Date
  71.  
  72.     Scots2January = DateSerial(Yr, 1, 2)
  73.  
  74. End Function
  75.  
  76. Public Function FirstAugustHoliday(Yr As Integer) As Date
  77.  
  78.     FirstAugustHoliday = DateSerial(Yr, 8, ((7 - Weekday(DateSerial(Yr, 8, 7))) + 2) Mod 7)
  79.     'DateSerial(Year(mydte), Month(mydte), ((7 - Weekday(DateSerial(Year(mydte), Month(mydte), 7))) + 2) mod 7)
  80.  
  81. End Function
  82.  
  83. Public Function LastAugustHoliday(Yr As Integer) As Date
  84.  
  85.     Dim TheDay As Integer
  86.  
  87.     TheDay = Day(DateSerial(Yr, 8, ((7 - Weekday(DateSerial(Yr, 8, 7))) + 2) Mod 7))     ' First Spring bank holiday
  88.  
  89.     TheDay = TheDay + 28
  90.     If TheDay <= 31 Then
  91.         LastAugustHoliday = DateAdd("d", 28, DateSerial(Yr, 8, ((7 - Weekday(DateSerial(Yr, 8, 7))) + 2) Mod 7))
  92.     Else
  93.         LastAugustHoliday = DateAdd("d", 21, DateSerial(Yr, 8, ((7 - Weekday(DateSerial(Yr, 8, 7))) + 2) Mod 7))
  94.     End If
  95.  
  96. End Function
  97.  
  98. Public Function ThanksgivingDay(Yr As Integer) As Date
  99.  
  100.     ThanksgivingDay = DateSerial(Yr, 11, 29 - Weekday(DateSerial(Yr, 11, 1), vbFriday))
  101.  
  102.  End Function
  103.  
Phil
Nov 14 '16 #6

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

Similar topics

4
by: Sondra Wilson | last post by:
I have created a sorted query. The total(records) I get in the query is correct. My problem lies with getting that total into my report. I use count to insert the total number of records in my...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
1
by: Punker | last post by:
Hi guys, I am trying to create export specifications for one of my queries. Now when I run the query on its own, it works perfectly. However when I try to export the data I get back the error...
8
by: s_wadhwa | last post by:
SELECT DISTINCTROW "01C" AS dummy, Buildings.BuildingNumber, UCASE(Buildings.BuildingName) AS BuildingName, Buildings.MasterPlanCode, Buildings.UniformBuildingCode,...
4
by: ShastriX | last post by:
Getting a weird error while trying out a query from Access 2003 on a SQL Server 2005 table. Want to compute the amount of leave taken by an emp during the year. Since an emp might be off for...
1
by: chitara | last post by:
is there any posibility to block mysql port or someting? I am getting "Error ,query failed" during adding any data through the admin panel of that website:-( same softwares(php, mysql and IIS)...
3
by: =?Utf-8?B?bXNjZXJ0aWZpZWQ=?= | last post by:
Has anyone successfully used an Access query from .NET? I am trying to do this and am getting a weird error. .NET calls queries 'stored procedures'. The error I am getting says "Schema could not be...
4
by: mrityunjay11 | last post by:
Error SQL query: CREATE TABLE per( item_name varchar, item_number int, payment_status int, payment_amount int, payment_currency int );
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
1
by: AccessBeetle | last post by:
SELECT DISTINCT .Contact1Index, Contacts., Contacts., Contacts., Contacts., Contacts.prefix, Contacts.Suffix, Contacts., Contacts., Contacts.city, Contacts.state, Contacts.zip, ., tblStatusCloseout.,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.