473,780 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateAdd Function - error when adding one year?

153 New Member
I'm using the date add function and for some reason I'm getting an error when I try to add a single year to a date but no error when I try to add more than a single year. can anyone figure out why this may be?

example: DateAdd("yyyy", 1, recSet7.Fields( "DateofContract "))
Jan 18 '07 #1
23 5024
cyberdwarf
218 Recognized Expert New Member
Hi Kosmos

this works for me
Expand|Select|Wrap|Line Numbers
  1. DateAdd("yyyy", 1,now)
Result: 18/01/2008 18:12:11

What does the 'Date' argument part of your call evaluate to?

HTH

Steve
Jan 18 '07 #2
Kosmos
153 New Member
hmmm....well the code checks to see if the renewal date of a contract is older than or equal to the current date...if so it sets renewal date to the renewal date plus the number of years the contract will renew for. This field is called "TermOfContract InYears" I am running into a problem here whenever this field is equal to 1. The following is the pertinent code:

[PHP] recSet7.Open "tblContrac ts", con7, adOpenKeyset, adLockOptimisti c
recSet7.MoveFir st
Do Until recSet7.EOF
If IsNull(recSet7. Fields("Renewal Date")) And recSet7.Fields( "TermOfContract InYears") <> 0 And recSet7.Fields( "ContinuousCont ract") = True Then
Do Until recSet7.Fields( "RenewalDat e") > Date
If recSet7.Fields( "TermOfContract InYears") = 1 Then
recSet7.Fields( "RenewalDat e") = DateAdd("yyyy", 1, recSet7.Fields( "DateofContract "))
recSet7.Fields( "RenewalDat e") = DateAdd("d", (-1), recSet7.Fields( "RenewalDat e"))
Else
recSet7.Fields( "RenewalDat e") = DateAdd("yyyy", recSet7.Fields( "TermOfContract InYears"), recSet7.Fields( "DateofContract "))
recSet7.Fields( "RenewalDat e") = DateAdd("d", (-1), recSet7.Fields( "RenewalDat e"))
End If
Loop
ElseIf Not IsNull(recSet7. Fields("Renewal Date")) And recSet7.Fields( "TermOfContract InYears") <> 0 And recSet7.Fields( "ContinuousCont ract") = True Then
If recSet7.Fields( "RenewalDat e") <= Date Then
Me.txtReference = recSet7.Fields( "DatabaseRefere nceNumber")
DoCmd.OpenQuery ("UpdateAddedTo Outlook")
Do Until recSet7.Fields( "RenewalDat e") > Date
If recSet7.Fields( "TermOfContract InYears") = 1 Then
recSet7.Fields( "RenewalDat e") = DateAdd("yyyy", 1, recSet7.Fields( "DateofContract "))
recSet7.Fields( "RenewalDat e") = DateAdd("d", (-1), recSet7.Fields( "RenewalDat e"))
Else
recSet7.Fields( "RenewalDat e") = DateAdd("yyyy", recSet7.Fields( "TermOfContract InYears"), recSet7.Fields( "DateofContract "))
recSet7.Fields( "RenewalDat e") = DateAdd("d", (-1), recSet7.Fields( "RenewalDat e"))
End If
Loop
End If
End If
recSet7.MoveNex t
Loop
recSet7.Close[/PHP]

Whenever TermOfContractI nYears is greater than 1, it goes on to the other option and it works which is why I have narrowed down the problem to the number 1 but perhaps it is my code that is causing the problem?
Jan 18 '07 #3
cyberdwarf
218 Recognized Expert New Member
Kosmos

What date is returned when you run
Expand|Select|Wrap|Line Numbers
  1. recSet7.Fields("DateofContract")
? and the contract term is one year?
Jan 18 '07 #4
cyberdwarf
218 Recognized Expert New Member
I assume you have added in the 1 year contract check to isolate the bug?
Expand|Select|Wrap|Line Numbers
  1.                 If recSet7.Fields("TermOfContractInYears") = 1 Then
  2.                     recSet7.Fields("RenewalDate") = DateAdd("yyyy", 1, recSet7.Fields("DateofContract"))
  3.                     recSet7.Fields("RenewalDate") = DateAdd("d", (-1), recSet7.Fields("RenewalDate"))
  4.                 Else
  5.                     recSet7.Fields("RenewalDate") = DateAdd("yyyy", recSet7.Fields("TermOfContractInYears"), recSet7.Fields("DateofContract"))
  6.                     recSet7.Fields("RenewalDate") = DateAdd("d", (-1), recSet7.Fields("RenewalDate"))
  7.                 End If
Can you give an example of what the DateAdd function returns for a 1-year contract and show the Date of Contract?

Steve
Jan 18 '07 #5
Kosmos
153 New Member
9/7/2005 is the specific date for this contract. Yes I did the if statements to isolate the problem.
Jan 18 '07 #6
cyberdwarf
218 Recognized Expert New Member
Yeah, but what date is the DateAdd function returning for 9/7/2005 ?
Jan 18 '07 #7
Kosmos
153 New Member
nothing it's freezing...sorr y...meant to reply to that question as well
Jan 18 '07 #8
cyberdwarf
218 Recognized Expert New Member
This works perfectly:
Expand|Select|Wrap|Line Numbers
  1. DateAdd("yyyy", 1,"09/07/2005"
Returns 09/07/2006

Howeever:
Expand|Select|Wrap|Line Numbers
  1. DateAdd("yyyy", 1,9/7/2005
Returns 30/12/1900 00:00:55

Maybe a matter of formatting the date before using DateAdd?

Steve
Jan 18 '07 #9
Kosmos
153 New Member
hmm well that would certainly make sense considering the loop would never end if it were going back in time. I'll mess around with it and let you know what I come up with. Thanks.
Jan 18 '07 #10

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

Similar topics

9
1574
by: Mark | last post by:
Hi - using asp and ms Access - this works ok: set Products = Server.CreateObject("ADODB.Recordset") Products.ActiveConnection = myConString Products.Source = "SELECT Products.productid, Products.product, Products.price, Products.partno FROM Products" Products.CursorType = 0 Products.CursorLocation = 2 Products.LockType = 3 Products.Open()
8
1706
by: Samuel | last post by:
I have a user complaining about a random error (sporadic, cannot be reliably reproduced): ================================= Microsoft VBScript runtime error '800a01fb' An exception occurred: 'objDict.add' =================================
4
2528
by: Chris Fairall | last post by:
Hi all I am using Visual Studio 2003 Enterprise Architect, and for them most part, everything has been working fine. However, in the last few days, I have been experiencing a weird error, and I was hoping someone might be able to shed some light on the cause, and a cure. When I have an existing solution with projects open, and I right-click on a project, and choose Add -> New Class..., I get the following error:
1
1369
by: Geraldine Hobley | last post by:
Hello, I'm having a problem adding a manifest to a vb project in order to add visual styles to my vb.net application. I followed the steps outlined her http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchUsingWindowsXPVisualStylesWithControlsOnWindowsForms.as This includes adding a resource to the exe fil However when I run the application I get the messag "Error while trying to run project unable to...
6
1199
by: Dacuna | last post by:
I have a dataset that I created programmatically and bind to a datagrid. When I add a row and I .show the form I get an error "Error creating window handle" This only happens if I have the code to add the row active. If I comment it out then the form loads successfully (without any records, obviously). Below is the code: '-----------------------------Code Starts
1
1309
by: ECathell | last post by:
I am getting an unspecified error when adding a windows form to a project. New project, old project. Doesn't matter. Also happens for user control. All the message box says is Unspecified Error. -- --Eric Cathell, MCSA
3
409
by: Codemonkey | last post by:
Hi, When I first installed Visual Studio 2003, I noticed I was getting the follow error when showing a form: A first chance exception of type 'System.ArithmeticException' occurred in system.drawing.dll Additional information: Overflow or underflow in the arithmetic operation It is being thrown on the line that attempts to add the controls to the
0
2365
by: =?Utf-8?B?QW5keSBZdQ==?= | last post by:
Hi, I'm trying to return exceptions from a WCF Service using FaultExceptions. I got the service compiled and running. But I get an error while adding a service reference to it. The error reads: " Attempting to download metadata from 'http://localhost:4619/WCFService1/Service.svc' using WS-Metadata Exchange or DISCO. Error: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension:
2
1960
by: Chris | last post by:
I am getting a viewstate error when adding dynamically user controls. SYSTEM_EXCEPTION:Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. My understanding is that the information about the controls getting posted back has to match the controls being created. When they don't match, this is what creates the error. The...
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10075
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.