在提交按钮中添加代码查找是否与数据库中记录重复即可 dim mrc as ADODB.recordset Private Sub cmdok_Click() txtSQL = "select * from tabelName where aa = '" & Trim(text1.Text) & "'" …… …… '执行查询 If Not mrc.RecordCount = 0 Then msgbox "重复添加"
Exit Sub End If End Sub
也可以通过按回车来确认 sub text1_keypress(keyascii as integer) if keyascii=13 then txtSQL = "select * from tabelName where aa = '" & Trim(text1.Text) & "'" …… …… '执行查询 If Not mrc.eof Then msgbox "重复添加"
if not rst.eof then
msgbox "此记录重复"
end if
=======================================根据 文本框的内容在数据库中查找 ,这样就行了
dim mrc as ADODB.recordset
Private Sub cmdok_Click()
txtSQL = "select * from tabelName where aa = '" & Trim(text1.Text) & "'"
……
…… '执行查询
If Not mrc.RecordCount = 0 Then
msgbox "重复添加"
Exit Sub
End If
End Sub
sub text1_keypress(keyascii as integer)
if keyascii=13 then txtSQL = "select * from tabelName where aa = '" & Trim(text1.Text) & "'"
……
…… '执行查询
If Not mrc.eof Then
msgbox "重复添加"
Exit Sub
end if
end ifend sub