VB设置注册用户要判断在ACCESS里面用户是否已存在,该在哪里添加那些代码?

数据库log.mdb,表名login,表里用户保存列名username,密码保存列名password。注册窗体Command1_Click()代码如下:PrivateSu... 数据库log.mdb,表名login,表里用户保存列名username,密码保存列名password。
注册窗体Command1_Click()代码如下:
Private Sub Command1_Click()
centerform Me
If Text1 = "" Then
MsgBox "请输入账号!", vbCritical, "错误"
Else
If Text1 <> "" And Text2 = "" Or Text3 = "" Then
MsgBox "请输入密码!", vbCritical, "错误"
Else
If Text2.Text <> Text3.Text Then
MsgBox "两次输入密码不一致!", vbCritical, "错误"
Else
If Text2.Text = Text3.Text Then
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\log.mdb "
sql = "select * from login"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.AddNew
rs.Fields("username").Value = Text1.Text
rs.Fields("password").Value = Text2.Text
rs.Update
rs.Close
conn.Close
MsgBox "注册成功,返回登陆界面!", vbExclamation, "提示"
Form1.Show
Unload Me
End If
End If
End If
End If
End Sub
展开
 我来答
曦者earth
2013-12-12 · TA获得超过142个赞
知道小有建树答主
回答量:182
采纳率:0%
帮助的人:226万
展开全部
只要写在连接数据库后,注册前就行吧
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\log.mdb "
——————————————————————————————————————————
rs.Open "SELECT * FROM login where username='" & Text1 & "'", conn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
MsgBox "用户名已存在!", vbCritical, "错误"
rs.Close
Exit Sub
End If
rs.Close
——————————————————————————————————————————
sql = "select * from login"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.AddNew
rs.Fields("username").Value = Text1.Text
rs.Fields("password").Value = Text2.Text
rs.Update
rs.Close
conn.Close
MsgBox "注册成功,返回登陆界面!", vbExclamation, "提示"
Form1.Show
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式