|
我用的不在列表中的代码,较为方便,用于不同的字段只要改一下表名即可。控件属性中标记为控件名也是表中字段名称,必须统一。Private Sub 材料_NotInList(NewData As String, Response As Integer)
Dim Rst As DAO.Recordset
Dim strName As String
Dim strMsg As String
strName = Me.ActiveControl.Tag
strMsg = "'" & NewData & "' is not an available '" & strName & "'"
strMsg = strMsg & "Do you want to associate the new Name to the current DLSAF?"
strMsg = strMsg & " Click Yes to link or No to re-type it."
Response = acDataErrContinue
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbYes Then
Set Rst = CurrentDb.OpenRecordset("材料表")
Rst.AddNew
Rst(strName) = NewData
Rst.Update
Rst.Close
Set Rst = Nothing
Me.Controls.Item(strName) = NewData
Me.Controls.Item(strName).Requery
Else
Me.Controls.Item(strName).Undo
End If
End Sub |
|