我正在Access 2010数据库中创建一个表单来输入员工用户。该代码还用于编辑现有用户。
为避免混淆 - 我将讨论的列名(存在于'Employees'表中)为LastName
和FirstName
,而我的表单上的输入字段是First
和Last
。
我创建的表单用于插入或更新员工数据。当用户输入First
字段时,Last
会自动填充LastName
列中FirstName = Me.First
列的值列表。如果管理员选择在框中填充的姓氏(而不是自己键入一个),则打开现有记录进行编辑。
Last
组合框
SELECT DISTINCT Last
FROM [Employees]
WHERE First = Forms![Employees]!First;
Last
combox更新后的代码Full
=“LastName
,FirstName
”)::
Private Sub Last_AfterUpdate()
Dim records As Recordset
Dim tmp As String
Dim db As Database
Set db = CurrentDb
If (DCount("Full", "Employees", "Full='" & Me.Last & "," & Me.First & "'") >= 1) Then
tmp = Me.Last & "," & Me.First
Set records = db.OpenRecordset("SELECT * from [Employees] WHERE Full = '" & tmp & "'")
Me.Recordset.FindFirst "ID1=" & records.Fields("ID1")
End If
If (DCount("Full", "Employees", "Full='" & Me.Last & ", " & Me.First & "'") >= 1) Then
tmp = Me.Last & ", " & Me.First
Set records = db.OpenRecordset("SELECT * from [Employees] WHERE Full = '" & tmp & "'")
Me.Recordset.FindFirst "ID1=" & records.Fields("ID1")
End If
End Sub
我的问题:
如果找到现有记录,则表示正确打开记录。但是,在打开记录之前,会使用管理员输入的数据保存一个新记录。这是问题,我不想保存数据,但我不知道为什么它首先发生。有没有办法阻止旧记录保存,除了以编程方式删除它?