窗体FrmLoginPublic blnLogin As Boolean Public lngCount As IntegerPrivate Sub CmdCancel_Click() Unload Me End SubPrivate Sub CmdOk_Click() blnLogin = LogTest() If blnLogin Then
Unload Me Else MsgBox "错误的用户名或密码!", vbOKOnly, "系统" End If End SubPrivate Sub Form_Load() blnLogin = False lngCount = 0 End SubPrivate Function LogTest() As Boolean Dim rs As ADODB.Recordset Dim strSql As String lngText = False strSql = "Select Uid, Ucode ,Pwd,UName From " & _ "Users where InUse=true and Ucode='" & Trim(TxtUser.Text) & "' " & _ " and Pwd='" & Trim(TxtPwd.Text) & "' "
Set rs = New ADODB.Recordset
On Error GoTo ErrHandle rs.CursorLocation = adUseClient
Public lngCount As IntegerPrivate Sub CmdCancel_Click()
Unload Me
End SubPrivate Sub CmdOk_Click()
blnLogin = LogTest()
If blnLogin Then
Unload Me
Else
MsgBox "错误的用户名或密码!", vbOKOnly, "系统"
End If
End SubPrivate Sub Form_Load()
blnLogin = False
lngCount = 0
End SubPrivate Function LogTest() As Boolean
Dim rs As ADODB.Recordset
Dim strSql As String
lngText = False
strSql = "Select Uid, Ucode ,Pwd,UName From " & _
"Users where InUse=true and Ucode='" & Trim(TxtUser.Text) & "' " & _
" and Pwd='" & Trim(TxtPwd.Text) & "' "
Set rs = New ADODB.Recordset
On Error GoTo ErrHandle
rs.CursorLocation = adUseClient
rs.Open strSql, Cn, adOpenStatic, adLockReadOnly, adCmdText
If Not (rs.EOF And rs.BOF) Then
gUid = rs.Fields("Uid")
gName = rs.Fields("UName")
LogTest = True
Else
TxtUser.SelStart = 0
TxtUser.SelLength = Len(TxtUser.Text)
TxtUser.SetFocus
TxtPwd.Text = ""
End If
rs.Close
Set rs = Nothing Exit Function
ErrHandle:
End Function在main()中加入这个窗体 frmLogin.show 1
'frmlogin.blnlogin=true 表示密码和用户名均正确
Set rs = New ADODB.Recordset
与
Dim rs As New ADODB.Recordset两种定义有什么区别?