Throughout my database when running reports i regular ask for date parameters, and convert these using the code provided by Allen Browne
I have one peice of code that i want to input a default date if the operator forgets to input the date.
But unfortunately this does not work correctly for me.
I have tried "01/02/2019" and #01/02/2019# but in both instancies the code fails to bring back the correct information.
Any help appreciated.
Code:
Function SQLDate(varDate As Variant) As String
'Purpose: Return a delimited string in the date format used natively by JET SQL.
'Argument: A date/time value.
'Note: Returns just the date format if the argument has no time component,
' or a date/time format if it does.
'Author: Allen Browne. allen@allenbrowne.com, June 2006.
If IsDate(varDate) Then
If DateValue(varDate) = varDate Then
SQLDate = Format$(varDate, "\#yyyy\/mm\/dd\#")
Else
SQLDate = Format$(varDate, "\#yyyy\/mm\/dd hh\:nn\:ss\#")
End If
End If
End Function
I have one peice of code that i want to input a default date if the operator forgets to input the date.
Code:
Startdate = SQLDate(InputBox("Please Enter the Start Date"))
If Len(Startdate) < 1 Then
Startdate = SQLDate(#1/2/2019#)
End If
But unfortunately this does not work correctly for me.
I have tried "01/02/2019" and #01/02/2019# but in both instancies the code fails to bring back the correct information.
Any help appreciated.