企业认识管理系统中的一段代码,老是报错:对象变量或with块变量未设置。在网上查到很多关于mrc.EOF报错的问题。但都没有找到解决方法。请高手指点。谢谢。~
Public Sub ShowData()
Dim j As Integer
Dim i As Integer Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then //这里~~~~~~~~~~~~
With msgList
.Rows = 1
Do While Not mrc.EOF
.Rows = .Rows + 1
For i = 1 To mrc.Fields.Count
Select Case mrc.Fields(i - 1).Type
Case adDBDate
.TextMatrix(.Rows - 1, i) = Format(mrc.Fields(i - 1) & "", "yyyy-mm-dd")
Case Else
.TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
End Select
Next i
mrc.MoveNext
Loop
End With
End If
mrc.Close
End Sub
Public Sub ShowData()
Dim j As Integer
Dim i As Integer Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then //这里~~~~~~~~~~~~
With msgList
.Rows = 1
Do While Not mrc.EOF
.Rows = .Rows + 1
For i = 1 To mrc.Fields.Count
Select Case mrc.Fields(i - 1).Type
Case adDBDate
.TextMatrix(.Rows - 1, i) = Format(mrc.Fields(i - 1) & "", "yyyy-mm-dd")
Case Else
.TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
End Select
Next i
mrc.MoveNext
Loop
End With
End If
mrc.Close
End Sub
返回的是个记录集吗?
如果是这样,那么你模块中ExecuteSQL函数的连接代码:
Set cnn = New ADODB.Connection
cnn.Open ConnectString
改为:
Set cnn = New ADODB.Connection
cnn.Open "Provider = SQLOLEDB.1;Persist Security Info = False;" & _
"User ID = sa;Password = ;Data Source = 127.0.0.1;" & _
"Initial Catalog = personnel" 其中的IP也可是安装SQL数据库的服务器名称