Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 函数忽略参数?_Ms Access_Vba - Fatal编程技术网

Ms access 函数忽略参数?

Ms access 函数忽略参数?,ms-access,vba,Ms Access,Vba,我在Access中有VBA函数,它应该根据我传递的字符串变量返回特殊文件夹(MyDocuments、Desktop等)的路径。但是,我总是得到公共桌面“C:\Users\public\desktop”,而不是我传入的。以下是功能代码: Function SpecialFolderPath(whichFolder As String) As String Debug.Print whichFolder Dim objWSHShell As Object Dim strSp

我在Access中有VBA函数,它应该根据我传递的字符串变量返回特殊文件夹(MyDocuments、Desktop等)的路径。但是,我总是得到公共桌面“C:\Users\public\desktop”,而不是我传入的。以下是功能代码:

Function SpecialFolderPath(whichFolder As String) As String
    Debug.Print whichFolder

    Dim objWSHShell As Object
    Dim strSpecialFolderPath

    Set objWSHShell = CreateObject("WScript.Shell")

    SpecialFolderPath = objWSHShell.SpecialFolders(whichFolder)

    Debug.Print SpecialFolderPath

    Set objWSHShell = Nothing
    Exit Function
ErrorHandler:

    MsgBox "Error finding " & strSpecialFolder, vbCritical + vbOKOnly, "Error"
End Function
因此,无论我以
哪个文件夹
的形式传入什么,我总是得到
C:\Users\Public\Desktop
。我怎样才能纠正这个问题

编辑:

我用以下方式调用此函数:
-
DoCmd.OutputTo一个输出查询,“BoxForecasting_作业”、“Excel工作簿(*.xlsx)”、特殊文件夹路径(“MyDocuments”)和“\BoxForecastByJobs.xlsx”、False、”、acExportQualityPrint

-
设置oWB=oXL.Workbooks.Open(SpecialFolderPath(“MyDocuments”)和“\BoxForecastByJobs.xlsx”)
更改此行:

SpecialFolderPath = objWSHShell.SpecialFolders(whichFolder)
致:

我对你的代码做了一些调整。添加了
WhichFolder=“Templates”
,使其成为子对象,并通过msgbox返回结果

我的最终结果是: 更改此行:

SpecialFolderPath = objWSHShell.SpecialFolders(whichFolder)
致:

我对你的代码做了一些调整。添加了
WhichFolder=“Templates”
,使其成为子对象,并通过msgbox返回结果

我的最终结果是:
这是一个收藏。使用for each循环查看其中的内容

Set wshshell = CreateObject("WScript.Shell")

For each thing in wshshell.SpecialFolders 
    wscript.echo thing
Next 
这些是它接受的名称

  • 冲积层

    AllUsersStartMenu

    冲积层程序

    诱惑启动

    桌面

    最爱

    字体

    我的文件

    幽冥

    印刷厂

    节目

    最近的

    森托

    开始菜单

    启动

    模板


这是一个收藏。使用for each循环查看其中的内容

Set wshshell = CreateObject("WScript.Shell")

For each thing in wshshell.SpecialFolders 
    wscript.echo thing
Next 
这些是它接受的名称

  • 冲积层

    AllUsersStartMenu

    冲积层程序

    诱惑启动

    桌面

    最爱

    字体

    我的文件

    幽冥

    印刷厂

    节目

    最近的

    森托

    开始菜单

    启动

    模板


是通过
Debug.Print()打印的正确路径吗?
?我正在测试您的代码。获取与您相同的返回。@LynnCrumbling-否,Debig.Print()显示的值相同。您可以添加调用代码吗?通过
Debug.Print()
打印的路径是否正确?我正在测试您的代码。获取与您相同的返回。@LynnCrumbling-No,Debig.Print()显示了相同的错误值。您可以添加调用代码吗?您给函数提供的是变量名而不是文本。您所做的更改对我没有任何影响
objWSHShell.SpecialFolders(whichfolders)
whichFolder=“MyDocuments”
的结果与
objWSHShell.SpecialFolders(“MyDocuments”)
的结果相同。只需确保您为函数提供的参数是一个文本。您为函数提供的是变量名而不是文本。您所做的更改对我没有任何影响
objWSHShell.SpecialFolders(whichfolders)
whichFolder=“MyDocuments”
的结果与
objWSHShell.SpecialFolders(“MyDocuments”)
的结果相同。只需确保为函数提供的参数是文本。