'Please add your own CommonDialog control Private Sub Command3_Click () Dim objFileSystem As Object Dim objExcelText As Object Dim strTableString As String, i As Integer, strFileName As String Dim pubConn As New ADODB.Connection Dim rsTable As New ADODB.Recordset Dim strConn As String Dim Strsql As String
strConn = "Provider = SQLOLEDB.1; Persist Security Info = False; User ID = develop; password = 12345; Data Source = ServerNmae" pubConn.Open strConn rsTable.CursorLocation = adUseClient strSQL = "select top 10 * from gate_register" rsTable. Open strSQL, pubConn, adOpenDynamic, adLockOptimistic For i = 0 To rsTable.Fields.Count - 1 strTableString = strTableString & rsTable.Fields (i) .Name & Chr (9) 'field name Get Next strTableString = strTableString & rsTable.GetString' Field name database record cmdialog.cancelerror = false cmdialog.FileName = "filename" 'default generated file name cmdialog.dialogtitle = "save export file" cmdialog.filter = "excel (* .xls) | * .xls | text File (* .dbf) | * .dbf | file file (* .doc) | * .doc | All files (*. *) | *. * "Cmdialog.defaultext =" * .xls "cmdialog.showsave strfilename = cmdialog .FileName Set objFileSystem = CreateObject ( "Scripting.FileSystemObject") Set objExcelText = objFileSystem.createtextfile (strFileName, True) objExcelText.writeline (strTableString) objE Xceltext.close Set ObjFileSystem = Nothingend Sub