Access 2016 NotInList将记录添加到表中,但必须退出表单并返回使用新记录 [英] Access 2016 NotInList adds record to table but have to exit form and go back in to use the new record
问题描述
我可以使用NotInList事件添加新记录,但是加载的记录中的所有数据仍然填充字段。必须退出表单并重新加载才能使用新记录。
I can add the new record with the NotInList event but all data from the record that was loaded is still populating the fields. Have to exit the form and reload to use the new record.
Private Sub CboPlan_NotInList(NewData As String,Response As Integer)
错误GoTo MicroSucks
Dim ans As String,strSQL As String
Dim db As Database
Private Sub CboPlan_NotInList(NewData As String, Response As Integer)
On Error GoTo MicroSucks
Dim ans As String, strSQL As String
Dim db As Database
设置db = CurrentDb()
Set db = CurrentDb()
设ans = MsgBox("Plan"& NewData&"不存在公司& strCoNam& vbCrLf& vbCrLf& "你要添加它吗?",vbYesNo)
Let ans = MsgBox("Plan " & NewData & " does not exist for company " & strCoNam & vbCrLf & vbCrLf & "Would you like to add it?", vbYesNo)
如果ans = vbYes然后
设strSQL =" INSERT INTO tblKEIP([CompID],[PlanNa])SELECT" &安培; lngCompID& ","" &安培; NewData& "';"
db.Execute strSQL,dbSeeChanges
响应= acDataErrAdded
否则
Response = acDataErrContinue
结束如果
If ans = vbYes Then
Let strSQL = "INSERT INTO tblKEIP ([CompID],[PlanNa]) SELECT " & lngCompID & ",'" & NewData & "';"
db.Execute strSQL, dbSeeChanges
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
退出P:
  ; DoCmd.SetWarnings True
设置db = Nothing
退出子
ExitP:
DoCmd.SetWarnings True
Set db = Nothing
Exit Sub
MicroSucks:
MsgBox"错误" &安培; Err.Number& ":" &安培;错误$
恢复退出P
简历
MicroSucks:
MsgBox "Error " & Err.Number & ": " & Error$
Resume ExitP
Resume
结束次
End Sub
推荐答案
添加新记录后,尝试使用Me.Requery刷新表单。希望它有所帮助......
Hi, After adding the new record, try using Me.Requery to refresh the form. Hope it helps...
这篇关于Access 2016 NotInList将记录添加到表中,但必须退出表单并返回使用新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!