我在Access 2010 VBA中嘗試從表中讀取記錄以將其寫入文本框中時出現問題。如何使用Access的OpenRecordset使用其數字鍵字段獲取記錄?
我的表是「產品」,其ProductID字段是數字。我之前使用過這種方法,但它僅適用於文本字段,而不適用於數字字段(ProductID爲自動編號)。
Private Sub GetProduct(ID As TextBox, Name As TextBox, Price As TextBox)
If ID <> "" Then
Set db = CurrentDb
Set rs = db.OpenRecordset("Productos", dbOpenDynaset)
'PROBLEM IS HERE
rs.FindFirst "ProductID=" & "'" & ID & "'"
If rs.NoMatch Then
MsgBox "The producto doesn't exist."
Price = ""
Name = ""
Else
Name = rs!ProductName
Price = rs!Price
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub
請幫助我。這是一個Final Proyect,我不知道其他,但這種方法。請幫幫我。
是的,但無論如何謝謝! – Josell 2013-04-07 23:24:40