Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

While running visual basic coding I am getting message that Run time error - 5: Invalid Procedure call or argument in Dateadd function. What is the problem and how to solve this.

syukei_start_date = Format(DateAdd("d", -7, Date), "yyyy/mm/dd") In this I am getting this error. Please help me.

What I have tried:

I am tried to change the date format, and directly gave the date in dateadd function. Nothing happen. Getting same error.
Posted
Updated 25-Sep-20 2:25am

1 solution

Similar problem here: windows 7 - Error calling dateadd function - Stack Overflow[^]

Example correct usage:
VB
Option Explicit

Private Sub Command1_Click()
  Dim datNow As Date
  Dim datYesterday As Date
  datNow = Now
  datYesterday = DateAdd("d", -1, datNow)
  Print "Yesterday = " & CStr(datYesterday)
End Sub

Private Sub Form_Load()
  MsgBox (DateAdd("d", -1, Now))
End Sub


Refer: [MS-VBAL]: DateAdd | Microsoft Docs[^]
VB
Function DateAdd(Interval As String, Number As Double, Date As Variant)


Once you have the desired date, convert that into a format needed.
 
Share this answer
 
Comments
Member 10556393 26-Sep-20 23:02pm    
Hi, this application runned successfully more than 4 years without this error. I got this error recently and if I want to change coding which you showed means I need to change minimum 300 modules. So i think it is not possible. Anyway I tried your coding it is working for testing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900