gpt4 book ai didi

database - docmd.transfertext 使用查询名称

转载 作者:搜寻专家 更新时间:2023-10-30 19:48:03 24 4
gpt4 key购买 nike

我正在尝试仅将表格中的特定数据导出到 CSV 文件。

如果我导出整个表,它会完美导出,但如果我尝试仅导出选定的数据,则什么也不会发生。我正在为要导出的数据使用查询名称。我没有收到任何错误消息,所以我不知道出了什么问题。

非常感谢任何帮助。

好吧,到目前为止我的代码如下..

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strQ As String
Dim Path As String
Dim CustomerId As String

Path = Me.TxFilePath.Value
CustomerId = Me.OpenArgs

Set dbs = CurrentDb

strSQL = "Select table.*" & _
"From table" & _
"Where table.[name] = 'CustomerId';"

Set qdf = dbs.CreateQueryDef("strQ", strSQL)
MsgBox CustomerId, vbOKOnly + vbInformation, "Export"

Set qdf = Nothing

DoCmd.TransferText acExportDelim, , strQ, Path, True

dbs.QueryDefs.Delete strQ
Set qdf = Nothing
dbs.Close
Set dbs = Nothing
End Sub

最佳答案

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strQ As String
Dim Path As String
Dim CustomerId As Integer

Path = Me.TxFilePath.Value
CustomerId = CInt(Me.OpenArgs)

strSQL = "Select *" _
& " From Table" _
& " Where Name = " & CustomerId & ""

Set dbs = CurrentDb

Set dbs = CurrentDb()
Set qdf = dbs.CreateQueryDef("strQ", strSQL)
Set qdf = Nothing
dbs.Close
Set dbs = Nothing

DoCmd.TransferText acExportDelim, , "strQ", Path, True

DoCmd.DeleteObject acQuery, "strQ"

关于database - docmd.transfertext 使用查询名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31111460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com