通过子过程传递函数

时间:2014-06-25 11:17:46

标签: access-vba

我正在尝试在运行子项目时调用一个函数,但是,我一直收到一条错误消息说"参数不是可选的",有人可以帮忙吗?

代码如下:

Public Sub ret()

Dim FSO As New Scripting.FileSystemObject

Const cstrFolderF = "\\tblSCFLAGCHECKER.txt"


           If FSO.FileExists(cstrFolderF) Then
           DoCmd.RunSQL "DELETE * FROM [tblSCFLAG_CHECKER]"
           DoCmd.TransferText acImportDelim, "tblSCFLAG_CHECKER", "tblSCFLAG_CHECKER", cstrFolderF, True
            changefieldnames
           Else
           'SCAnswer = MsgBox("SC Flags does not exist, do you wish to continue?", vbYesNo Or vbQuestion Or vbDefaultButton2)
        'If SCAnswer = vbNo Then Exit Sub
        End If
        End Sub

Private Sub changefieldnames()


Dim db As Database
Dim tdf As TableDef
Dim n As Object

Set db = CurrentDb
Set tdf = db.TableDefs("tblSCFLAG_CHECKER")
  For Each n In tdf.Fields
    If n.Name = "?Person ID" Then n.Name = "Person ID"
  Next n

Set tdf = Nothing
Set db = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

您的changefieldnames函数需要两个参数,但在

后的调用中不提供任何参数
       DoCmd.TransferText acImportDelim, "tblSCFLAG_CHECKER", "tblSCFLAG_CHECKER", cstrFolderF, True
        changefieldnames

作为评论:您应该尝试调试代码,而不是仅发布错误,甚至没有说明错误发生的位置。