【问题标题】:Function call on left-hand side of assignment must return variant or object error赋值左侧的函数调用必须返回变量或对象错误
【发布时间】: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


【解决方案1】:

很奇怪,但是我导出了模块,然后导入了它,现在它工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 2012-06-29
    • 2012-07-06
    • 1970-01-01
    • 2018-08-10
    相关资源
    最近更新 更多