Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
565 views
in Technique[技术] by (71.8m points)

ms access - "Save as..." dialog box in MSAccess vba: how?

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:able.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.

Is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

FileDialog Properties

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

Also: How do I get a single file name out of a File Dialog object in VBA (for MS Access 2007)?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...