将值插入表/显示重复项

时间:2015-04-30 11:53:21

标签: vba ms-access access-vba

当我在表格中插入表格中的值时,表格中的第一个值始终使用表格字段中列出的值进行更新。 我使用下面的代码: ++++++++++++++++++++++++++++++++++++++++++++++++

Private Sub Command114_Click()



If (Me.VehicleNumber = "" Or Me.vMake = "" Or Me.vModel = "") Then
MsgBox "Please fill required fields", vbInformation, "Information"
Else

CurrentDb.Execute "INSERT INTO [Vehicles]([VehicleNumber], [Make], [Model], [PurchasedMiles], [PurchasePrice], [PurchaseLocation], [PurchaseDate], [VehicleNotes])" & _
"VALUES ('" & Me.vVehicleNumber & "', '" & Me.vMake & "', '" & Me.vModel & "', '" & Me.vPurchasedMiles & "', '" & Me.vPurchasePrice & "', '" & Me.vPurchaseLocation & "', '" & Me.vPurchaseDate & "', '" & Me.vVehicleNotes & "')"

MsgBox "Vehicle Added", vbInformation, "Information"

End If


End Sub

enter image description here 请查看图片。

谢谢:D

1 个答案:

答案 0 :(得分:1)

我认为每当您输入正在修改现有数据的数据时,您的表单都会受到限制。

如果要手动插入,请将表单的记录源值设置为空。

goto forms's property > Data section> Record Source > delete any    entry there

或者让表格有界。并使用新的记录功能添加新记录。你甚至不需要手动插入功能。 Access会自动为您保存。