运行时错误“ 5”:使用全局变量时

时间:2018-06-26 15:44:56

标签: vba ms-access access-vba ms-access-2013

我在Module1中声明了全局变量,当我试图在另一个模块中使用它时,它显示运行时错误'5':\无效的过程调用或参数。我找不到问题,请提供此问题的解决方案  声明全局变量:

Function getFilePath() As String
 getFilePath = FilePath
 Set FilePath = "C:\quadyster\R3AgreementDetails"
End Function

实现全局变量:

Private Sub SendAgreement_Click()
 If (Not IsNull(Me.RequestFrom) And Not IsNull(Me.RequestReference)) Then
 Call AttachR3ServiceAgreement(Module1.FilePath, tripObjectFormation, "Agreement")
Me.AgreementDate = Now()

Else
 MsgBox "Please provide 'RequestFrom' and 'RequestReference' to proceed." & vbNewLine & vbNewLine & _
            "Press Ok to continue.", vbOKOnly, "Alert!!!"
End If
End Sub

这是调用函数

Public Function AttachR3ServiceAgreement(FilePath As String, tripData As 
  tripDetails, requestType As String)

发生错误:       设置objStream = objFSO.OpenTextFile(fileHTML,ForReading)

1 个答案:

答案 0 :(得分:0)

您在这里遇到语法错误:Set仅可用于对象。

Public FilePath As String
Function getFilePath() As String
  FilePath = "C:\quadyster\R3AgreementDetails"
  getFilePath = FilePath 
End Function

Private Sub SendAgreement_Click()
 If (Not IsNull(Me.RequestFrom) And Not IsNull(Me.RequestReference)) Then
 Call AttachR3ServiceAgreement(Module1.FilePath, tripObjectFormation, "Agreement")
Me.AgreementDate = Now()

Else
 MsgBox "Please provide 'RequestFrom' and 'RequestReference' to proceed." & vbNewLine & vbNewLine & _
            "Press Ok to continue.", vbOKOnly, "Alert!!!"
End If
End Sub