“另存为...”对话框MSAccess vba:怎么样? [英] "Save as..." dialog box in MSAccess vba: how?
本文介绍了“另存为...”对话框MSAccess vba:怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MSAccess中我有一个带按钮的面具。当用户单击按钮时,表中的数据将导出为.txt文件:
Private Sub Command_Click()
Dim Rst As DAO.Recordset
Dim AField As DAO.Field
Dim TempStr As String
Dim FileNumber
FileNumber = FreeFile
打开c: \\ table.txt输出为#FileNumber
设置Rst = CurrentDb.OpenRecordset(Tabella1,dbOpenForwardOnly)
尽管不是Rst.EOF
对于每个AField在Rst.Fields
If(AField.Name<>ID)Then
TempStr = TempStr& AField.value&
End If
Next
打印#FileNumber,Left(TempStr,Len(TempStr) - 1)
TempStr =
Rst.MoveNext
循环
Rst.Close
设置Rst = Nothing
关闭#FileNumber
End Sub
它的工作原理,但我会显示一个另存为...对话框,允许用户选择导出数据的文件。
可以吗?
解决方案
您可以设置对Microsoft Office xx对象库的引用,并使用FileDialog。
Sub ShowFileDialog()
/ pre>
Dim dlgOpen As FileDialog
设置dlgOpen = Application.FileDialog(msoFileDialogSaveAs)
使用dlgOpen
.InitialFileName =Z:\docs\
.Show
结束
End Sub
另外:如何从VBA中的文件对话框对象中获取单个文件名(对于MS Access 2007 )?
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.
Is it possible?
解决方案You can set a reference to the Microsoft Office x.x Object Library and use FileDialog.
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)?
这篇关于“另存为...”对话框MSAccess vba:怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文