VBA +传输文本 +规格名称

发布于 2024-10-31 02:16:40 字数 697 浏览 0 评论 0原文

以下是我的 DoCmd.TransferText 的样子

oCmd.TransferText TransferType:=acExportDelim, _
            SpecificationName:="Schema.ini", _
            TableName:="BASIC_DATA_Query", _
            FileName:="BASIC_DATA_Query_Result.txt", _
            HasFieldNames:=False

当我将“schema.ini”作为我的规范名称时,出现错误

“运行时错误'3625':文本文件 规范“Schema.ini”不 存在。您不能导入、导出或 使用规范的链接。”

即使在参考本文之后:http://support.microsoft.com/kb/ 241477

我无法解决该问题。我的“Schema.ini”与数据库位于同一文件夹中

- 是一个包含我所有结果的查询,我需要将其导出到文件中。 BASIC_DATA_Query_Result.txt 的标题和字段由制表符分隔,

可能的解决方案是什么?

The following is what my DoCmd.TransferText looks like

oCmd.TransferText TransferType:=acExportDelim, _
            SpecificationName:="Schema.ini", _
            TableName:="BASIC_DATA_Query", _
            FileName:="BASIC_DATA_Query_Result.txt", _
            HasFieldNames:=False

When I give the "schema.ini" as my specification name, I get an error

"Run-time error '3625': The text file
specification 'Schema.ini' does not
exist. You cannot import, export, or
link using the specification."

Even after referring to this article: http://support.microsoft.com/kb/241477

I have not been able to resolve the problem. My 'Schema.ini' is in the same folder as the DB.

BASIC_DATA_Query - is a query which has all my results and I need that to be exported to the file BASIC_DATA_Query_Result.txt with header and fields separated by tabs.

What is the possible solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素食主义者 2024-11-07 02:16:40

VBA 似乎有问题,这是自 2004 年以来的一个已知问题:(。

无论如何,我编写了导出代码,这解决了我的问题。我将代码发布在这里供其他人

Sub ExportTextFileDelimited(FileName As String, _
    DataSet As String, _
    Delimiter As String, _
    TextQualifier As String, _
    WithFieldNames As Boolean)
    On Error GoTo ExportTextFile_Err

    Dim cnn As ADODB.Connection
    Dim rst As New ADODB.Recordset

    Dim Directory As String
    Dim MyString As String, strSQL As String
    Dim strDS As String
    Dim I As Integer

    Open FileName For Output As #1
    Set cnn = CurrentProject.Connection

    rst.Open DataSet, cnn, adOpenForwardOnly, adLockReadOnly
    If WithFieldNames Then
        For I = 0 To rst.Fields.Count - 1
            MyString = MyString & TextQualifier & rst(I).Name & TextQualifier & Delimiter
        Next I
        MyString = Left(MyString, Len(MyString) - 1)
        Print #1, MyString
    End If
    rst.MoveFirst
    Do While Not rst.EOF
        MyString = ""
        For I = 0 To rst.Fields.Count - 1
            'check for text datatype (202)
            If rst(I).Type = 202 Then
                MyString = MyString & TextQualifier & _
                rst(I) & TextQualifier & Delimiter
            Else
                MyString = MyString & rst(I) & Delimiter '<----
            End If
        Next I
            MyString = Left(MyString, Len(MyString) - 2) '<---
        Print #1, MyString & TextQualifier
        rst.MoveNext
    Loop

ExportTextFile_Exit:
    ' Close text file.
    Close #1
    rst.Close
    Set cnn = Nothing
    Exit Sub
ExportTextFile_Err:
    MsgBox Err.Description
    Resume ExportTextFile_Exit
End Sub

使用:

调用 ExportTextFileDelimited("C:\Query.txt" , "查询", vbTab, """", True)

There seems to be a problem with VBA, a know issue since 2004 :(.

Anyway I wrote code to export and that resolved my problem. Am posting the code here for anyone else

Sub ExportTextFileDelimited(FileName As String, _
    DataSet As String, _
    Delimiter As String, _
    TextQualifier As String, _
    WithFieldNames As Boolean)
    On Error GoTo ExportTextFile_Err

    Dim cnn As ADODB.Connection
    Dim rst As New ADODB.Recordset

    Dim Directory As String
    Dim MyString As String, strSQL As String
    Dim strDS As String
    Dim I As Integer

    Open FileName For Output As #1
    Set cnn = CurrentProject.Connection

    rst.Open DataSet, cnn, adOpenForwardOnly, adLockReadOnly
    If WithFieldNames Then
        For I = 0 To rst.Fields.Count - 1
            MyString = MyString & TextQualifier & rst(I).Name & TextQualifier & Delimiter
        Next I
        MyString = Left(MyString, Len(MyString) - 1)
        Print #1, MyString
    End If
    rst.MoveFirst
    Do While Not rst.EOF
        MyString = ""
        For I = 0 To rst.Fields.Count - 1
            'check for text datatype (202)
            If rst(I).Type = 202 Then
                MyString = MyString & TextQualifier & _
                rst(I) & TextQualifier & Delimiter
            Else
                MyString = MyString & rst(I) & Delimiter '<----
            End If
        Next I
            MyString = Left(MyString, Len(MyString) - 2) '<---
        Print #1, MyString & TextQualifier
        rst.MoveNext
    Loop

ExportTextFile_Exit:
    ' Close text file.
    Close #1
    rst.Close
    Set cnn = Nothing
    Exit Sub
ExportTextFile_Err:
    MsgBox Err.Description
    Resume ExportTextFile_Exit
End Sub

Usage:

Call ExportTextFileDelimited("C:\Query.txt", "Query", vbTab, """", True)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文