用VB做的一个添加用户的模块.代码是:
Private Sub cmdOK_Click()
On Error GoTo DealError
Dim txtSQL As String
Dim MsgText As String
Dim objRs As New Recordset
Dim objCn As New Connection
With objCn
.Provider = "SQLOLEDB"
strSQL = "User ID=sa;PWD=123;Server=(local);database=计算机组成原理"
.ConnectionString = strSQL
.Open '打开连接
End With
If ThisUserName <> "Admin" Then
'判断用户的权限
MsgBox "只有超级管理员才有此权限!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
If Trim(Text1(0).Text) = "" Then
'判断用户名输入是否为空
MsgBox "请输入用户名!", vbOKOnly + vbExclamation, "警告"
Exit Sub
Text1(0).SetFocus
Else
txtSQL = "select * from 用户信息"
Set objRs.ActiveConnection = objCn
objRs.Open (strSQL)
While (objRs.EOF = False)
If Trim(objRs.Fields(0)) = Trim(Text1(0)) Then
'判断是否有重复记录
MsgBox "用户已经存在,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
Text1(0).SetFocus
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Exit Sub
Else
objRs.MoveNext
End If
Wend
End If
If Trim(Text1(1).Text) <> Trim(Text1(2).Text) Then
'判断两次所输入的密码是否一致
MsgBox "两次输入密码不一样,请确认!", vbOKOnly + vbExclamation, "警告"
Text1(1).SetFocus
Text1(1).Text = ""
Text1(2).Text = ""
Exit Sub
Else
If Text1(1).Text = "" Then
'判断密码输入是否为空
MsgBox "密码不能为空!", vbOKOnly + vbExclamation, "警告"
Text1(1).SetFocus
Text1(1).Text = ""
Text1(2).Text = ""
Else
objRs.AddNew
'添加用户
objRs.Fields(0) = Trim(Text1(0).Text)
objRs.Fields(1) = Trim(Text1(1).Text)
If OpComm.Value = True Then
objRs.Fields(2) = 0
Else
objRs.Fields(2) = 1
End If
Set objRs = Nothing
objCn.Update
objCn.Close
Me.Hide
MsgBox "添加用户成功!", vbOKOnly + vbExclamation, "添加用户"
End If
End If
DealError:
ShowError "程序执行出错,错误信息如下:" & vbCrLf & Err.Description
End Sub
每次运行都出错啊.说是User附近有语法错误.我是刚学的VB好多都不懂,头都大拉
请各位帮帮忙吧.谢谢咯