"另存为..."对话框中MSACCESS VBA:怎么了?另存为、对话框中、QUOT、MSACCESS

2023-09-08 10:57:10 作者:给你一口甜甜

在MSACCESS我有一个按钮的面具。当用户点击该按钮时,在一个表中的数据导出上.txt文件:

In MSAccess I've a mask with a button. When the user clicks on the button, the data in a table are exported on a .txt file:

Private Sub Command_Click()
Dim Rst As DAO.Recordset
Dim AField As DAO.Field
Dim TempStr As String
Dim FileNumber
FileNumber = FreeFile
Open "c:\table.txt" For Output As #FileNumber
Set Rst = CurrentDb.OpenRecordset("Tabella1", dbOpenForwardOnly)
Do While Not Rst.EOF
    For Each AField In Rst.Fields
        If (AField.Name <> "ID") Then
            TempStr = TempStr & AField.value & "    "
        End If
    Next
    Print #FileNumber, Left(TempStr, Len(TempStr) - 1)
    TempStr = ""
    Rst.MoveNext
Loop
Rst.Close
Set Rst = Nothing
Close #FileNumber
End Sub

它的工作原理,但我会通过允许用户选择其上导出数据的文件显示一个另存为...对话框。

It works, but I would display a "Save as..." dialog box by allowing the user to choose the file on which export the data.

这可能吗?

推荐答案

您可以设置引用到Microsoft Office XX对象库,并使用FileDialog的。

You can set a reference to the Microsoft Office x.x Object Library and use FileDialog.

FileDialog的属性

Sub ShowFileDialog()
    Dim dlgOpen As FileDialog
    Set dlgOpen = Application.FileDialog(msoFileDialogSaveAs)
    With dlgOpen
        .InitialFileName = "Z:\docs\"
        .Show
    End With
End Sub

另外:How我在VBA得到一个文件名从文件对话框的对象(的MS Access 2007)?