2015-08-28 100 views
0

我有這樣的代碼在VBA:VBA訪問編譯:方法或數據成員未找到

Private Sub cmdAdd_Click() 
    'when we click on button Add there are two options 
    '1. for insert 
    '2. for update 
    If Me.Barcode & "" = "" Then 
     'this is for insert new 
     'add data to table 
     CurrentDb.Execute "INSERT INTO tab_barcodeki([date], [time], category, barcode) " & _ 
       " VALUES(" & Me.Date & ",'" & Me.Time & "','" & _ 
       Me.Category & "','" & Me.Barcode & "')" 
    Else 
     'otherwise (Tag of barcode store the id of liquid to be modified) 
     CurrentDb.Execute "UPDATE tab_barcodeki " & _ 
       " SET [date]=" & Me.Date & _ 
       ", [time]='" & Me.Time & "'" & _ 
       ", category='" & Me.Category & "'" & _ 
       ", barcode='" & Me.Barcode & "'" & _ 
       " WHERE barcode=" & Me.Barcode.Tag 

    End If 

    'clear form 
    cmdClear_Click 
    'refresh data in list on form 
    tab_barcodekisubform.Form.Requery 
End Sub 

我編譯時編譯有錯誤,方法或數據成員未找到。我已經檢查過表格列和文本框的名稱,文本框鏈接是相同的。 你有什麼想法的解決方案?

感謝

回答

0

替換像Me.DateMe!Date引用。

這適用於Me.DateMe.Time,Me.Barcode,Me.Category

Me.Barcode.Tag替換爲Me!Barcode.Tag

您可以使用.來僅引用真正的屬性。所以Me.Date預計表格具有Date屬性 - 它沒有,所以你得到的錯誤。引用表單成員的名稱時,請使用!而不是點。

+0

我沒有提到,但現在我有另一個編譯錯誤:「Invalid or unqualified reference」when I want Edit function like Me!Date = .Fields(「date」) –

+0

@RóbertVizi - 你有字段名爲'date '?也許你可以嘗試將它重命名爲'date1'或'CreationDate',因爲AFAIK,'date'是保留字。 – miroxlav

+0

是的字段名爲日期,但我不想重命名它,因爲它取決於許多查詢。但插入,刪除,更新功能工作正常,只是我得到編譯錯誤消息。所以謝謝 –

相關問題