R
Rhonda Fischer
Hello,
I am using a function to return a date value and the
only value that seems to return is 00:00:00 when I
would have expected 2004-03-09 00:00:00.000 in full.
However all I really need is the day, month, year value
to use in a subsequent DateDiff operation.
Thank you for any suggestions that you may have.
Kind Regards
Rhonda
==========================================================
Code I use to call my function:
==========================================================
=> want to work out the first function call
If (Not myDateFrom = fnCheckDateFromExists(incidentNo))
Then
If (Not myDateTo = fnCheckDateToExists
(incidentNo)) Then
txtDaysLost = DateDiff(d, myDateFrom, myDateTo)
Else
txtDaysLost = DateDiff(d, myDateFrom, Date)
End If
Else
'If (Not myIncidentDate = fnIncidentDateExists
(incidentNo)) Then
'txtDaysLost = DateDiff(d, myIncidentDate,
getDate())
'Else
'txtDaysLost = 0
'End If
End If
==========================================================
My First Function:
==========================================================
Function fnCheckDateFromExists(inIncidentNo) As Date
On Error GoTo Err_fnCheckDateFromExists
'Form: frmIncidentDetailsEdit
'Event: On_Load
'Declaration
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
'Open the connection
cnn.Open "Provider=sqloledb; Data
Source=ZSQUIRREL;Initial Catalog=HealthAndSafety;
Integrated Security=SSPI"
'Set up the Command objects's Connection, SQL and
parameter types
With cmd
.ActiveConnection = cnn
.CommandText = "SELECT DaysLostFrom FROM
tblIncident WHERE IncidentID = ?"
.CreateParameter , adInteger, adParamInput,
50 'IncidentID
End With
cmd.Parameters(0) = inIncidentNo
Set rst = cmd.Execute
'An empty recordset means the Incident does NOT have a
DaysLostFrom value
fnCheckDateFromExists = rst!DaysLostFrom
cnn.Close
Set cnn = Nothing
Set cmd = Nothing
Exit_fnCheckDateFromExists:
Exit Function
Err_fnCheckDateFromExists:
MsgBox Err.Description
Resume Exit_fnCheckDateFromExists
End Function
I am using a function to return a date value and the
only value that seems to return is 00:00:00 when I
would have expected 2004-03-09 00:00:00.000 in full.
However all I really need is the day, month, year value
to use in a subsequent DateDiff operation.
Thank you for any suggestions that you may have.
Kind Regards
Rhonda
==========================================================
Code I use to call my function:
==========================================================
=> want to work out the first function call
If (Not myDateFrom = fnCheckDateFromExists(incidentNo))
Then
If (Not myDateTo = fnCheckDateToExists
(incidentNo)) Then
txtDaysLost = DateDiff(d, myDateFrom, myDateTo)
Else
txtDaysLost = DateDiff(d, myDateFrom, Date)
End If
Else
'If (Not myIncidentDate = fnIncidentDateExists
(incidentNo)) Then
'txtDaysLost = DateDiff(d, myIncidentDate,
getDate())
'Else
'txtDaysLost = 0
'End If
End If
==========================================================
My First Function:
==========================================================
Function fnCheckDateFromExists(inIncidentNo) As Date
On Error GoTo Err_fnCheckDateFromExists
'Form: frmIncidentDetailsEdit
'Event: On_Load
'Declaration
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
'Open the connection
cnn.Open "Provider=sqloledb; Data
Source=ZSQUIRREL;Initial Catalog=HealthAndSafety;
Integrated Security=SSPI"
'Set up the Command objects's Connection, SQL and
parameter types
With cmd
.ActiveConnection = cnn
.CommandText = "SELECT DaysLostFrom FROM
tblIncident WHERE IncidentID = ?"
.CreateParameter , adInteger, adParamInput,
50 'IncidentID
End With
cmd.Parameters(0) = inIncidentNo
Set rst = cmd.Execute
'An empty recordset means the Incident does NOT have a
DaysLostFrom value
fnCheckDateFromExists = rst!DaysLostFrom
cnn.Close
Set cnn = Nothing
Set cmd = Nothing
Exit_fnCheckDateFromExists:
Exit Function
Err_fnCheckDateFromExists:
MsgBox Err.Description
Resume Exit_fnCheckDateFromExists
End Function