我建立了一个TABLE,有两个字段:“aa”文本型字段,“bb”日期型字段。
bb字段的有效性规则是:不要求输入,Is Null 或 >#1980-01-01# 或"" 。
在VB中用两个TEXT控件,通过一个DATA控件分别绑定上述两个字段。采用如下代码,其中command1 command2为两个命令按钮private sub command1_click()
if data1.recordset.recordcount=0 then
data1.recordset.addnew
else
data1.recordset.edit
end if
text1.enabled=true
text2.enabled=true
end subprivate sub command2_click()
data1.recordset.update
text1.enabled=false
text2.enabled=false
end subprivate sub form_load()
text1.enabled=false
text2.enabled=falseend sub当执行上述程序时,增加一条记录:text1中为“abvd", text2中为"1999-09-09"
按command2后执行正常。
当按command1后,修改上述记录时,将text2中的内容清空,然后按command2,则出现如下错误:
3426 被关联对象取消
该错误也没有任何帮助信息。
请教各位大侠如何解决?
bb字段的有效性规则是:不要求输入,Is Null 或 >#1980-01-01# 或"" 。
在VB中用两个TEXT控件,通过一个DATA控件分别绑定上述两个字段。采用如下代码,其中command1 command2为两个命令按钮private sub command1_click()
if data1.recordset.recordcount=0 then
data1.recordset.addnew
else
data1.recordset.edit
end if
text1.enabled=true
text2.enabled=true
end subprivate sub command2_click()
data1.recordset.update
text1.enabled=false
text2.enabled=false
end subprivate sub form_load()
text1.enabled=false
text2.enabled=falseend sub当执行上述程序时,增加一条记录:text1中为“abvd", text2中为"1999-09-09"
按command2后执行正常。
当按command1后,修改上述记录时,将text2中的内容清空,然后按command2,则出现如下错误:
3426 被关联对象取消
该错误也没有任何帮助信息。
请教各位大侠如何解决?
Private Sub Text2_LostFocus()
On Error GoTo ErrInfo
If CDate(Text2.Text) < CDate("1980-1-1") Then
MsgBox "日期必须大于《1980-1-1》", , "系统提示"
Text2.Text = ""
Text2.SetFocus
End If
If Trim(Text2.Text) = "" Then
MsgBox "日期必须填写", , "系统提示"
Text2.Text = ""
Text2.SetFocus
End If
ErrInfo:
MsgBox "格式错误,应如《2000-01-01》", , "系统提示"
Text2.Text = ""
Text2.SetFocus
End Sub
On Error GoTo ErrInfo
If CDate(Text2.Text) < CDate("1980-1-1") Then
MsgBox "日期必须大于《1980-1-1》", , "系统提示"
Text2.Text = ""
Text2.SetFocus
End If
If Trim(Text2.Text) = "" Then
MsgBox "日期必须填写", , "系统提示"
Text2.Text = ""
Text2.SetFocus
End If
Exit Sub '应该有这句话吧?呵呵~
ErrInfo:
MsgBox "格式错误,应如《2000-01-01》", , "系统提示"
Text2.Text = ""
Text2.SetFocus
End Sub