Private Sub cmdOk_Click()UserName = "sa"If Trim(txtUserName.Text = "") ThenMsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"txtUserName.SetFocusElsesql = "select * from userpwd where U_name = " & "'" & txtUserName.Text & "'"Set rs = ExecuteSQL(sql, msgtxt)If rs.EOF = True Then (这里出了问题)MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"txtUserName.SetFocusElseIf Trim(rs.Fields(1)) = Trim(txtPassword.Text) ThenOK = TrueUserName = Trim(txtUserName.Text)UserPass = Trim(txtPassword.Text)rs.CloseMe.HideElseMsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"txtPassword.SetFocustxtPassword.Text = ""End IfEnd IfEnd IfExecuteSQL函数Public Function ExecuteSQL(ByVal sql _As String, MsgString As String) _As ADODB.Recordset'executes SQL and returns RecordsetDim cnn As ADODB.ConnectionDim rst As ADODB.RecordsetDim sTokens() As StringOn Error GoTo ExecuteSQL_ErrorsTokens = Split(sql)Set cnn = New ADODB.Connectioncnn.Open ConnectStringIf InStr("INSERT,DELETE,UPDATE,EXECUTE", _UCase$(sTokens(0))) Thencnn.Execute (sql)MsgString = sTokens(0) & _" query successful"ElseSet rst = New ADODB.Recordsetrst.Open Trim$(sql), cnn, _adOpenKeyset, _adLockOptimistic'rst.MoveLast 'get RecordCountSet ExecuteSQL = rstMsgString = "查询到" & rst.RecordCount & _" 条记录 "End IfExecuteSQL_Exit:Set rst = NothingSet cnn = NothingExit FunctionExecuteSQL_Error:MsgString = "查询错误: " & _Err.DescriptionResume ExecuteSQL_ExitEnd Function我也不会调试。据说是VB If mrc.EOF = True Then 实时错误 91 据说ExecuteSQL函数出问题,可以帮我改下么。谢谢你,很急~
2 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
将出问题的地方按下面修改:
If rs.RecordCount = 0 Then
MsgBox "没有这个用户,请重新输入用户名
rs.EOF是记录集的结束标记
忽然笑
TA贡献1806条经验 获得超5个赞
Dim w_s As String, w_d As String, sp() As String
Function cc()
Dim i As Integer
w_s = "a,b,c,d,e,f,g,h"
sp = Split(w_s, ",", -1)
For i = LBound(sp) To UBound(sp)
MsgBox sp(i)
Next
End Function
Private Sub Command1_Click()
Call cc
End Sub
添加回答
举报
0/150
提交
取消