📄 frmadduser.frm
字号:
VERSION 5.00
Begin VB.Form frmAddUser
BorderStyle = 3 'Fixed Dialog
Caption = "adduser"
ClientHeight = 2715
ClientLeft = 2760
ClientTop = 3750
ClientWidth = 5625
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2715
ScaleWidth = 5625
ShowInTaskbar = 0 'False
Begin VB.TextBox txtPassword
Height = 375
IMEMode = 3 'DISABLE
Left = 2280
PasswordChar = "*"
TabIndex = 3
Top = 840
Width = 2055
End
Begin VB.TextBox txtUsername
Height = 375
Left = 2280
TabIndex = 1
Top = 240
Width = 2055
End
Begin VB.CommandButton CancelButton
Caption = "&cancel"
Height = 375
Left = 3360
TabIndex = 5
Top = 1920
Width = 1215
End
Begin VB.CommandButton OKButton
Caption = "&add"
Default = -1 'True
Height = 375
Left = 1320
TabIndex = 4
Top = 1920
Width = 1215
End
Begin VB.Label Label2
Caption = "&password:"
Height = 615
Left = 1320
TabIndex = 2
Top = 960
Width = 1215
End
Begin VB.Label Label1
Caption = "&username:"
Height = 375
Left = 1320
TabIndex = 0
Top = 360
Width = 1095
End
End
Attribute VB_Name = "frmAddUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub Form_Activate()
txtUsername.SetFocus
End Sub
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Open strCn
End Sub
Private Sub OKButton_Click()
Set rs = New ADODB.Recordset
rs.Open "select * from users where username='" & txtUsername.Text & "'", cn, adOpenDynamic
If rs.EOF <> True Then
MsgBox "username is already exist, add error!", vbExclamation, "add user error"
Else
rs.Close
rs.Open "users", cn, adOpenKeyset, adLockOptimistic, adCmdTable
rs.AddNew
rs.Fields(1) = txtUsername.Text
rs.Fields(2) = txtPassword.Text
rs.Update
MsgBox "add ok!", vbInformation, "add user ok"
rs.Close
End If
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.SetFocus
End Sub
Private Sub txtPassword_LostFocus()
If Len(txtPassword.Text) > 30 Or Len(txtPassword.Text) < 6 Then
MsgBox "the length of password need between 6 and 30.", vbCritical, "length error"
End If
End Sub
Private Sub txtUsername_gotfocus()
txtUsername.SelStart = 0
txtUsername.SelLength = Len(txtUsername.Text)
End Sub
Private Sub txtPassword_gotfocus()
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
End Sub
Private Sub txtUsername_LostFocus()
If Len(txtUsername.Text) > 30 Then
MsgBox "the length of username need less 30.", vbCritical, "over length error"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -