我有一个表单,如果一个字段为空,它会告诉用户它不能为空,并为用户提供填写空白字段(是)或关闭表单(否)的选项。问题是,当用户选择“否”(或关闭表格)时,它给我一个运行时错误2585。经过研究,我让它使用“ On Got Focus”检查该字段是否为空。 (在该字段上执行更新后不起作用,因为如果为空,则没有更新。)这是我的代码:
If IsNull(Me.txtSSN) Then
strMsg = "Social Security Number Must Not Be Left Blank!" & vbCrLf
strMsg = strMsg & "Do you want to add new veteran's record?" & vbCrLf
If MsgBox(strMsg, vbQuestion + vbYesNo, "Go to Record?") = vbYes Then
Me.Undo
Me.Refresh
Me.txtSSN.SetFocus
Exit Sub
Else
Me.Undo
Me.Refresh
Me.txtSSN.SetFocus
'DoCmd.OpenForm "fmuMainMenu"
DoCmd.Close acForm, "frmVetNewMainForm"
End If
其他 其余代码...