首页 > 解决方案 > 运行时错误“5”:使用全局变量时

问题描述

我在 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)

这里发生错误: Set objStream = objFSO.OpenTextFile(fileHTML, ForReading)

标签: ms-accessvbams-access-2013

解决方案


你有一个语法错误: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

推荐阅读