2017-07-24 108 views
0

我得到一個錯誤,如果條件(我猜日期差異),但我想不出原因。Microsoft Access VBA Datediff錯誤

錯誤狀態:無效的過程調用或參數。

現在:格式爲DD.MM.YYYY HH當前系統時間:MM:SS

原點:是從格式DD.MM.YYYY HH表的日期:MM :SS

Public Function ImportDateCheckSpec(eing As String) As error 
    Dim datum As Date 
    Dim error As New error 
    error.Success = True 
    error.Code = 2 
    error.Message = "There has been a problem with the given Date. This might be due to:" + vbCrLf + " *The date is befor the current date. " + vbCrLf + " *The date is in the wrong format." 

    Debug.Print 4 

On Error GoTo Fail 
    datum = CDate(eing) 
    Debug.Print datum 
    Debug.Print Now 

    If (DateDiff("Day", Now, datum) < 0) Then '<----- Here is the error 
     Debug.Print 2 
     error.Success = False 
     Set ImportDateCheckSpec = error 
    End If 
    Exit Function 

Fail: 
    Debug.Print 3 
    error.Success = True 
    Set ImportDateCheckSpec = error 
    Exit Function 
End Function 
+0

'Day'是無效的:'則DateDiff( 「d」,現在,基準)' - 注意' 「99999」'會通過你的測試... –

+0

'Error'是關鍵詞,強烈建議您用其他方法改變它。最好在模塊聲明中使用'Option Explicit'。轉到選項>>需要變量聲明才能激活它。 –

+0

謝謝,爲什麼「99999」會通過? – Lukas

回答

1

你的參數上則DateDiff不正確。試試這個:

If (DateDiff("d", Now, datum) < 0) Then '<----- Here is the error