注册 登录
编程论坛 VB6论坛

“当前范围内的声明重复”这个错误怎么改?

清泉照晚 发布于 2006-09-03 19:42, 4208 次点击


Private Sub cmdCancel_Click()
OK = False
Me.Hide
End Sub


Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim mrc As New ADODB.Recordset
Dim MsgText As String
'ToDo: create test for correct password
'check for correct password

UserName = ""
If Trim(txtUserName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
OK = True
mrc.Close
Me.Hide
UserName = Trim(txtUserName.Text)
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPassword.SetFocus
txtPassword.Text = ""
End If
End If
End If

miCount = miCount + 1
If miCount = 3 Then
Me.Hide
End If
Exit Sub
End Sub

上面这段代码有什么错误??运行的时候老是出现“当前范围内的声明重复”,错误指在红色字体的那一行。怎么改啊??

5 回复
#2
syh8782006-09-03 19:54
去掉 Dim mrc As ADODB.Recordset
#3
清泉照晚2006-09-03 20:13
去掉    Dim mrc As ADODB.Recordset  这一句了,错误又变成“ 对象关闭时,不允许操作”了,怎么办啊?
#4
yeshirow2006-09-03 22:32

錯誤原因, 在相同作用域重復使用 Dim 語句聲明 mrc 變數.

將那句寫爲:
Set mrc = new ADODB.Recordset

#5
syh8782006-09-04 08:13

你把 ExecuteSQL过程代码贴出来

[此贴子已经被作者于2006-9-4 8:14:11编辑过]

#6
杨颖2013-06-07 00:12
你好,同学,你的这个问题解决了么?我现在也碰到这个问题了,我后天就要交作业了,您能不能有时间帮我一下呢?
1