2016-07-27 86 views
-2

當我嘗試編譯我的代碼時,我總是收到「類型聲明字符」錯誤,但我不明白爲什麼。類型聲明字符錯誤 - MS Access

下面的代碼(轉述):

Private Sub cboTest_AfterUpdate() 

'(some code) 

Dim strWhere As String 
Dim lngLen As Long 

lngLen = Len(strWhere - 5) 

strWhere = Left$(strWhere, lngLen) 

'(some code) 

End Sub 

是我工作的.ACCDB文件大約爲7000 KB,它已編制好幾次前到現在,但由於某種原因,這個每次迭代給我的問題。任何想法可能是什麼問題?

由於提前,

Ĵ

+1

在Access 2010中,我得到一個不同的編譯錯誤行'lngLen = Len(strWhere - 5)':「需要的變量 - 不能分配給這個表達式」。你實際上是不是指'lngLen = Len(strWhere) - 5'? –

回答

1

這在這裏運行,不到風度失敗的短字符串:

Private Sub cboTest_AfterUpdate() 

    Dim strWhere As String 
    Dim lngLen As Long 

    lngLen = Len(strWhere) - 5   
    If lngLen >= 0 Then 
     strWhere = Left(strWhere, lngLen) 
    End If 

    '(some code) 

End Sub