编译显示变量未定义,初学者求救

黑桃D 2011-03-10 08:18:47

Private Sub cmdLogin_Click()
Dim objRecordset As ADODB.Recordset
Dim strSQL As String

strSQL = "select UserName from Users where UserName='" & _
Trim(txtUserName.Text) & ""
Set objRecordset = ExecuteSQL(strSQL)
If objRecordset.EOF = True Then
MsgBox "用户名错误!", vbExclamation + vbOKOnly, "警告"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
UserName = objRecordset.Fields(0)

strSQL = "select UserName from Users where Password='" & _
Trim(txtPassword.Text) & ""
Set objRecordset = ExecuteSQL(strSQL)
If objRecordset.EOF = True Or UserName <> objRecordset.Fields(0) Then
MsgBox "密码错误!", vbExclamation + vbOKOnly, "警告"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If

mdiMain.Show
Unload Me
End Sub

VB6.0+access
UserName那里编译显示变量未定义,是在案例书上弄的一个登陆程序。
...全文
181 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
黑桃D 2011-03-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 clear_zero 的回复:]

VB code

Private Sub cmdLogin_Click()
Dim objRecordset As ADODB.Recordset
Dim strSQL As String
dim UserName as string
strSQL = "select UserName from Users where UserName='" & _
……
[/Quote]
新问题:实时错误'91' 对象变量或With 块变量未设置
调试 13行
If objRecordset.EOF = True Then


显示黄色
黑桃D 2011-03-10
  • 打赏
  • 举报
回复
新问题:实时错误'91' 对象变量或With 块变量未设置
调试 13行
If objRecordset.EOF = True Then
显示黄色
黑桃D 2011-03-10
  • 打赏
  • 举报
回复
UserName =   这里提示变量未定义 是论坛的字体颜色来着,请无视
clear_zero 2011-03-10
  • 打赏
  • 举报
回复

Private Sub cmdLogin_Click()
Dim objRecordset As ADODB.Recordset
Dim strSQL As String
dim UserName as string
strSQL = "select UserName from Users where UserName='" & _
Trim(txtUserName.Text) & ""
Set objRecordset = ExecuteSQL(strSQL)
If objRecordset.EOF = True Then
MsgBox "用户名错误!", vbExclamation + vbOKOnly, "警告"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
UserName = objRecordset.Fields(0)

strSQL = "select UserName from Users where Password='" & _
Trim(txtPassword.Text) & ""
Set objRecordset = ExecuteSQL(strSQL)
If objRecordset.EOF = True Or UserName <> objRecordset.Fields(0) Then
MsgBox "密码错误!", vbExclamation + vbOKOnly, "警告"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If

mdiMain.Show
Unload Me
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧