注册 登录
编程论坛 VB6论坛

请问:如何通过VB6.0+Access编写一个登陆窗口,当输入正确的用户名和密码时,就登陆

wujingyi 发布于 2006-06-18 12:01, 2619 次点击
请问:如何通过VB6.0+Access编写一个登陆窗口,当输入正确的用户名和密码时,就登陆到主窗口中。
10 回复
#2
wujingyi2006-06-18 13:40
最好能附上源码
#3
wujingyi2006-06-18 14:51
ding
#4
purana2006-06-18 14:57

''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'程 序 员 : 梁 嘉 辉
'编 写 时 间 : 2006-5-17
'模 块 功 能 : 实现多用户登录
'E - Mail : myfend_liang@yahoo.com.cn
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Dim g_Connect As ADODB.Connection
Dim g_Recordset As ADODB.Recordset

Private Sub Command1_Click()
Static userCount As Integer
Dim i As Integer
For i = 0 To 2
If Text1(i).Text = "" Then
MsgBox "內容不能為空,請輸入!", vbExclamation + vbOKOnly
Text1(i).SetFocus
Exit Sub
End If
Next
If Text1(1).Text <> Text1(2).Text Then
MsgBox "兩次密碼不正確,請重新輸入"
Text1(1).SetFocus
Exit Sub
End If
Set g_Recordset = CreateObject("ADODB.Recordset")
Dim sql As String
sql = "SELECT * FROM user_info WHERE 用戶名='" & Text1(0).Text & "'"
g_Recordset.Open sql, g_Connect, adOpenKeyset, adLockPessimistic
If g_Recordset.RecordCount <= 0 Then
MsgBox "沒有此用戶,請重新輸入!", vbCritical + vbOKOnly
userCount = userCount + 1
g_Recordset.Close
'Exit Sub
Else
If Text1(1).Text = g_Recordset.Fields("密碼").Value Then
MsgBox "密碼正確,登錄成功!", vbOKCancel
Form2.Show
g_Recordset.Close
Unload Me
Else
MsgBox "密碼不正確,請確定密碼!"
Text1(1).SetFocus
userCount = userCount + 1
'Exit Sub
End If
End If
If userCount >= 3 Then
MsgBox "你已經超出使用權限了,不能再使用本軟件!"
End
End If
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim iConnstr As String
Set g_Connect = CreateObject("ADODB.Connection")
iConnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\student.mdb;Persist Security Info=False"
g_Connect.Open iConnstr
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set g_Connect = Nothing
Set g_Recordset = Nothing
End Sub


只有本站会员才能查看附件,请 登录

#5
wujingyi2006-06-18 16:23

能写上注释吗

#6
shj994222006-06-23 15:31
谢谢
#7
moshen622006-06-24 13:39
这个在VB里就有的 是模版窗体叫登陆窗体
#8
xiataoyong2007-09-15 15:59
好!太好了!
#9
lsdrxc2010-01-09 20:30
谢谢
#10
e3bnsd2012-12-03 20:47
非常 好。学习了。
#11
zzq702012-12-05 15:57
4楼附的程序以下载,在VB中运行提示如下错误:编译错误,变量未定义
Private Sub Form_Load()
    DataGrid1.Columns(0).Width = 1500
    DataGrid1.Columns(1).Width = 100
End Sub
1