写了将sudu julian日期YDDD转换为常规日期DD / MM / YYYY的函数。
当表单填充时,我得到一个#Type!如果字段没有数据,则在txt_estimated_delivery_date中。
如果有数据则一切正常。
在函数的第一行停止我打开表单,我看到函数没有被调用,直到有数据要转换,其他所有人都得到#Type!。
功能中的错误处理程序并不好,因为只有在出于某种原因存在数据时才会调用它。
我需要在表格或控件中进行纠错?
控制记录来源
= JDateToDate([estimated_shipping_date])
Function JDateToDate(JDate As String) As Long
Dim TheYear As Integer
Dim TheDay As Integer
Dim TheDate As Long
TheYear = CInt(Left(JDate, 1))
If TheYear < 30 Then
TheYear = TheYear + 2010
Else
TheYear = TheYear + 1900
End If
TheDay = CInt(Right(JDate, 3))
TheDate = DateSerial(TheYear, 1, TheDay)
JDateToDate = TheDate
End Function
答案 0 :(得分:1)
该函数需要一个String,该类型不支持Null。试试这段代码。
Function JDateToDate(JDate) As String
Dim TheYear As Integer
Dim TheDay As Integer
If IsNull(JDate) Then
JDateToDate = vbNullString
Exit Function
End If
TheYear = CInt(Left(JDate, 1))
If TheYear < 30 Then
TheYear = TheYear + 2010
Else
TheYear = TheYear + 1900
End If
TheDay = CInt(Right(JDate, 3))
JDateToDate = DateSerial(TheYear, 1, TheDay)
End Function