微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

transfertext无法写入文件,因为它已被锁定

如何解决transfertext无法写入文件,因为它已被锁定

我正在vba中进行工作,以便将Access 2016中的一系列查询导出到表单文本字段中指定的文件夹中。我正在使用transfertext。每次代码尝试执行该行时,都会创建该文件,但没有写入任何内容,并且会出现错误:“ Access数据库引擎无法打开或写入文件'[filename]'。另一个用户,或者您需要查看和写入其数据的权限”。当我出去删除文件时,我不能,因为MS Access正在使用它,并且一直保持这种状态,直到Access被关闭

我可以使用保存的规范通过向导手动将文件导出到该位置,或者保存的导出没有问题。

我已经完成了

的故障排除步骤
  1. 每个人都可以完全控制写入文件文件夹“ C:\ Temp”
  2. 传递给传输文本的每个变量都是正确的
  3. 将每个变量替换为固定值
  4. 代码未在中断模式下运行
  5. 查询返回记录

这是代码。它出现在DoCmd.TransferText行。

    On Error GoTo Err_Func
    Dim strPathFile As String
    Dim strQryName As String
    Dim strStation As String
    Dim bolExp As Boolean 'check for all the data for queries
    Dim bolErr As Boolean 'check to see if error has occured
    bolErr = False
   
    'format the output folder string
    If IsNull(txtOutputLocation) Then
        txtOutputLocation = GetoutputLoc
    End If
    If Right(txtOutputLocation,1) <> "\" Then
        txtOutputLocation = txtOutputLocation & "\"
    End If
    DoCmd.SetWarnings False
    For Each itm In lstExportQueries.ItemsSelected
        UpdStatus "Exporting " & lstExportQueries.ItemData(itm),False
        'set the saving location and name
        strPathFile = txtOutputLocation & lstExportQueries.ItemData(itm) & ".txt"
        DoCmd.TransferText acExportFixed,lstExportQueries.Column(1,itm),lstExportQueries.ItemData(itm),strPathFile,False
        'troubleshooting - replace all variables with fixed inputs
        'DoCmd.TransferText acExportFixed,"exp_Result Export Specification","exp_Result","C:\Temp\exp_Result.txt",False
    Next
  
    
Exit_Func:
    DoCmd.SetWarnings True
    
    UpdStatus "Complete",True
    Exit Sub
    

Err_Func:
    MsgBox Err.Description
    UpdStatus "Error generating summary",False
    bolErr = True
    Resume Next

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。