前言
机房敲了一个半月了,之前总是一直修改,需要好好的总结一下,首先是登陆窗体。
登陆窗体:
问题及重点代码:
1.问题1实时错误’3704’ 对象关闭时,不允许操作
出现这个问题是因为前面写了代码mrc.Close导致后面mrc1调用mrc数据集里面的内容时无法调用。
Trim函数用来删除一个字符串的字头或字尾,删除字符串首尾的空白
End Sub 和Exit Sub的区别:
end sub 是一个过程的结束代码(每一个SUB中必须对应一个END SUB)Exit Sub 是在过程内代码执行时,可选择性的退出过程执行(即不执行Exit sub之后的代码,相当于中途退出的意思),这不是必须的。
所以代码编写的时候不要随便乱加Exit Sub
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim txtSQL1 As String
Dim txtSQL2 As String
Dim mrc As ADODB.Recordset '连接user表
Dim mrc1 As ADODB.Recordset '连接onwork表
Dim mrc2 As ADODB.Recordset '连接worklog表
Dim MsgText As String
If Trim(txtUserName.Text = "") Then
MsgBox "文本框不能输入为空!", vbOKOnly, "提示"
txtUserName.Text = ""
txtPassword.Text = ""
End If
If Trim(txtPassword.Text = "") Then
MsgBox "文本框不能输入为空!", vbOKOnly, "提示"
txtUserName.Text = ""
txtPassword.Text = ""
End If
txtSQL = "select * from user_Info where userID = '" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly, "提示"
txtUserName = ""
txtPassword = ""
Exit Sub
End If
txtSQL = "select * from user_Info where user_PWD = '" & txtPassword.Text & "'and UserID = '" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "密码输入不正确,请重新输入密码!", vbOKOnly, "提示"
txtUserName = ""
txtPassword = ""
Exit Sub
End If
If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
Me.Hide
Else
MsgBox "密码不正确,请重新输入密码!", vbOKOnly, "提示"
End If
miCount = miCount + 1 '登陆限制
If miCount > 3 Then
MsgBox "登陆超过次数限制!", vbOKOnly, "提示"
End If '结束条件语句
txtSQL1 = "select * from OnWork_Info "
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.AddNew
mrc1.Fields(0) = Trim(txtUserName.Text)
mrc1.Fields(1) = mrc.Fields(2)
mrc1.Fields(2) = Date
mrc1.Fields(3) = Time
mrc1.Update
mrc1.Close
txtSQL2 = "select * from worklog_Info"
Set mrc2 = ExecuteSQL(txtSQL2, MsgText)
mrc2.AddNew
mrc2.Fields(0) = Trim(txtUserName) 'Trim函数用来删除一个字符串的字头或字尾,删除字符串首尾的空白
mrc2.Fields(1) = mrc.Fields(2)
mrc2.Fields(2) = Date
mrc2.Fields(3) = Time
mrc2.Update
mrc2.Close
MsgBox "登陆成功!", vbOKOnly, "提示"
Me.Hide
frmMain.Show
End Sub
Private Sub Form_Load()
txtUserName.FontSize = txtUserName.FontSize + 10
txtPassword.FontSize = txtPassword.FontSize + 10
Me.Width = Screen.Width * 0.4
Me.Height = Screen.Height * 0.5
Left = 0 ' 在水平方向上居中显示。
Top = 0 ' 在垂直方向上居中显示
End Sub