[求助]为什么同样的代码在不同的地方,其中一个就会出问题
为什么同样的代码在不同的地方,其中一个就会出问题 Private Sub Command1_Click() Dim mrc As ADODB.Recordset txtsql = "select username from use where username='" & Trim(Text1.Text) & "'" Set mrc = ExecuteSQL(txtsql) If mrc.EOF = True Then MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告" Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) Exit Sub End If username = mrc.Fields(0) txtsql = "select username from use where password='" & Trim(Text2.Text) & "'" Set mrc = ExecuteSQL(txtsql) If mrc.EOF = True Then MsgBox " 密码错误!", vbExclamation + vbOKOnly, "警告" Text2.SetFocus Text2.SelStart = 0 Text2.SelLength = Len(Text2.Text) Exit Sub End If MDIFrmyingye.Show Unload Me -------------------------------------------------------------------------------------------------- 以上代码一切正常 Option Explicit Dim txtsql1 As String Private Sub cmdbaocun_Click() Dim www As Integer If Len(Text1.Text) <> 8 Then www = MsgBox("您输入的时间格式不正确,请核实从新输入!", vbOKOnly, "警告!") Text1.SetFocus Exit Sub End If Dim mrc As ADODB.Recordset txtsql1 = "select 日期 from 日报单 where 日期='" & Text1.Text & "'" Set mrc = ExecuteSQL(txtsql1) If mrc.EOF = False Then实时错误‘91’对象变量或with变量没有定义 www = MsgBox("已经存在该学号的记录,学号不能重复!", vbExclamation + vbOKOnly, "警告") Text1.SetFocus mrc.Close End If End Sub |