【发布时间】:2014-04-14 14:43:55
【问题描述】:
我已经在 excel vba 中开发一个程序有一段时间了,没有任何错误。然而,今天,adter 只注释掉了 sub 之外的内容,我的所有函数现在都会抛出 Function call on left-hand side of assignment must return variant or object error 错误。请参阅下面的示例:
Public Function fGetEmployees() As Variant()
Dim oDB As ADODB.Connection
Dim oCM As ADODB.Command
Dim oRS As ADODB.Recordset
Dim strSQL As String
On Error GoTo Err:
strSQL = "SELECT StaffId, FirstName, LastName " & _
"FROM ptqEmployees"
Set oDB = New ADODB.Connection
oDB.Open gcConn
Set oCM = New ADODB.Command
With oCM
.ActiveConnection = oDB
.CommandText = strSQL
.CommandType = adCmdText
Set oRS = .Execute
End With
fGetEmployees = oRS.GetRows()
oRS.Close
Set oRS = Nothing
oDB.Close
Set oRS = Nothing
Exit Function
Err:
Call fLogDBError(Err.Number, Err.Description, 4)
End Function
在线抛出错误:
fGetEmployees = oRS.GetRows()
正如所说,这已经有一段时间没有问题了。也没有调试选项。
谁能帮忙解决这个问题?
【问题讨论】:
-
将
Function fGetEmployees() As Variant()更改为Function fGetEmployees() As Variant -
@simoco 谢谢,我现在收到错误
Only comments may appear after End Sub, End Function, or End Property。我已经检查了整个模块,肯定没有 cmets 不合适 -
oRS.GetRows()应该是oRS.GetRows
标签: vba excel compiler-errors