📄 frmreg.frm
字号:
VERSION 5.00
Begin VB.Form frmReg
Caption = "DB Login - WWJD? "
ClientHeight = 1680
ClientLeft = 60
ClientTop = 345
ClientWidth = 4125
LinkTopic = "Form1"
ScaleHeight = 1680
ScaleWidth = 4125
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtUserName
Height = 285
Left = 1800
TabIndex = 2
Top = 480
Width = 2175
End
Begin VB.TextBox txtPassword
Height = 285
IMEMode = 3 'DISABLE
Left = 1800
PasswordChar = "*"
TabIndex = 1
Top = 840
Width = 2175
End
Begin VB.CommandButton Command1
Caption = "&Login"
Height = 375
Left = 2880
TabIndex = 0
Top = 1200
Width = 1095
End
Begin VB.Label Label1
Caption = "UserName:"
Height = 255
Left = 360
TabIndex = 4
Top = 480
Width = 1215
End
Begin VB.Label Label2
Caption = "Password"
Height = 255
Left = 360
TabIndex = 3
Top = 840
Width = 1215
End
End
Attribute VB_Name = "frmReg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rs As New ADODB.Recordset 'rs is the recordset that is used to check the username & password
Dim sql As String 'used to handle the sql statment
Dim sConn As String 'Connection String
Dim iChances As Integer ' 3 Strikes Counter
Private Sub Command1_Click()
'Tell vb what database to use
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Sample.mdb" & ";Persist Security Info=False"
'This is where the username and password are checked within the database
sql = "SELECT * FROM tblLogin Where Username ='" & txtUserName.Text & _
"' And Password ='" & txtPassword.Text & "'"
'Open the recordset for use in the login
rs.Open sql, sConn, adOpenDynamic, adLockReadOnly, adCmdText
If Not rs.EOF Then
Form2.Show 'Login was sucessful now show another form
Unload Me ' Unload this one
Else
'The login failed
MsgBox "Wrong username or password", , "Login Error"
iChances = iChances + 1 ' Another chance gone
If iChances = 3 Then Unload Me ' All chances gone
End If
'Close the recordset
rs.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -