可以先用该随机数到数据库中检索一下,看是否有记录存在,如果不存在则运行下步
Function IsExistNumber(ByRef conn, theNumber)
Dim rs
'建立查询
Set rs = conn.Execute("select * from 表名 where 随机数字段名 = " & theNumber)
'记录判断
if rs.eof and rs.bof then
IsExistNumber = false
else
IsExistNumber = true
end if
'关闭对象
Set rs = Nothing
End Function
'Simple(其中conn是数据连接对象)
if NOT IsExistNumber(conn, 1234) then
执行数据插入操作
else
其他操作
end if