这些代码我有点不理解。
以下是一个验证身份的登录窗体的代码。
用虚线包起来的这些我不是很明白,每当我运行之后都报一个相同的错误:
(实时错误91 -----对像变量或with块变量未设置。)
报错行我已标记如下。
???为什么没有看见连接sql server2000的代码呢。真是奇怪啊。(这个实例是以sql server 200 做的数据库。)
请各位指点迷津,小弟不胜感激。
========================================================================
////////////////////////////////////////////////////////////////////////
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
txtUserName.Text = Left$(sBuffer, lSize)
Else
txtUserName.Text = vbNullString
End If
End Sub
/////////////////////////////////////////////////////////////////////////
==========================================================================
Private Sub cmdCancel_Click()
OK = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
'ToDo: create test for correct password
'check for correct password
Dim txtSQL As String
Dim mrc As 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