简体   繁体   English

Access VBA是否使用与登录用户不同的凭据来访问网络文件夹?

[英]Does Access VBA use different credentials than logged in user to access network folder?

I'm trying to link to an Excel spreadsheet from a Microsoft Access 2016 database. 我正在尝试从Microsoft Access 2016数据库链接到Excel电子表格。 I was given permission to the folder that contains the Excel spreadsheet and am able to create/open/edit files there now. 我被授予包含Excel电子表格的文件夹的权限,并且现在能够在其中创建/打开/编辑文件。 The problem with linking this spreadsheet is the worksheet name will change without notice (it's exported from another program). 链接此电子表格的问题是工作表名称将更改而不会另行通知(它是从另一个程序导出的)。

I can create a linked table in the Access GUI to the Excel spreadsheet and queries run fine, but when the worksheet name changes the link is broken. 我可以在Access GUI中创建到Excel电子表格的链接表,并且查询运行良好,但是当工作表名称更改时,链接断开。 I thought I can just delete and re-link the spreadsheet, or delete/re-import each time the Access database is opened using the DoCmd.TransferSpreadsheet method but I get error 3051: File is locked or you don't have permission (paraphrased). 我以为我可以删除并重新链接电子表格,或者每次使用DoCmd.TransferSpreadsheet方法打开Access数据库时都可以删除/重新导入,但我收到错误3051:文件被锁定或您没有权限(解释为)。

I know the code works because I moved the spreadsheet to a different shared folder of mine and it links perfectly. 我知道代码有效,因为我将电子表格移动到了我的其他共享文件夹中,并且可以完美链接。 I put a test spreadsheet in the folder I need to access and it gives me the same error. 我将测试电子表格放在需要访问的文件夹中,它给了我同样的错误。

So it works everywhere except the folder I need it to work in. Everything seems to me to be pointing to a permissions problem but my Sys Admin says that's not the issue. 因此它可以在除我需要使用的文件夹之外的任何地方使用。在我看来,所有内容都指向权限问题,但我的系统管理员说这不是问题。

Why does it work from the GUI but not the VBA? 为什么从GUI而不是VBA起作用? I know for certain the file isn't open by anyone/anything. 我知道可以肯定该文件不能被任何人打开。 Does the VBA use different credentials than the logged in user? VBA是否使用与登录用户不同的凭据?

It fails on this line: DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblWeeklySeniorityReport", StrXls, True 它在以下行上失败:DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel9,“ tblWeeklySeniorityReport”,StrXls,True

that command is importing, not linking. 该命令正在导入,而不是链接。 when you have a file on a network share, assume it can be open my multiple people. 当您在网络共享上有一个文件时,假设它可以同时打开多个人。 folder permissions can also come into play. 文件夹权限也可以发挥作用。 I would copy the file locally, and then import it. 我将在本地复制文件,然后将其导入。 use filecopy, then try the import 使用filecopy,然后尝试导入

I figured it out. 我想到了。

We have multiple Access DBs running from Windows Scheduled Tasks. 我们有多个通过Windows计划任务运行的Access DB。 The problem with this task is that it was set to "Run with Highest Privileges". 该任务的问题在于它被设置为“以最高特权运行”。 It must run this way with some sort of admin user which wasn't given permissions to the folder it needs to access. 它必须以某种管理员用户的身份运行,该用户未获得对其需要访问的文件夹的权限。 I unchecked this box and it runs with the logged in user creds, which does have access to the folder. 我取消选中此框,它以登录的用户凭据运行,该凭据确实有权访问该文件夹。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM