Private sub command4_click ()
Dim RS as new ADODB. recordset
Dim SQL as string
Dim connstr as string
Connstr = "provider = Microsoft. Jet. oledb.4.0;" & "Data Source =" & App. Path & "/data. mdb ;"
'*************************************** **************************************** ****************
Dim application as object
Dim workbook as object
Dim sheet as object
'*************************************** **************************************** ****************
Select case label12.caption
Case "all"
SQL = "select * from Members"
Conn. Open (connstr)
Rs. Open SQL, Conn, 1, 1
If Rs. recordcount = 0 then
Msgbox "no record"
Rs. Close
Conn. Close
Exit sub
Else
With commondialog1
. Dialogtitle = "enter an Excel name"
. Filter = "Microsoft Office Excel Workbook (*. xls) | *. xls"
. Showsave
End
If commondialog1.filename = "" Then exit sub
Set Application = Createobject ("Excel. application") 'create an Excel Object
Workbooks. Add
Activeworkbook. saveas (commondialog1.filename)
Set workbook = application. workbooks. Open (commondialog1.filename)
Set sheet = Workbook. Sheets. Add () 'to create a new form
For t = 1 to Rs. recordcount
Sheet. cells (T, 1). value = Rs. Fields (1). value' write data to excel
Sheet. cells (T, 2). value = Rs. Fields (2). value' write data to excel
Sheet. cells (T, 3). value = Rs. Fields (3). value' write data to excel
Sheet. cells (T, 4). value = Rs. Fields (4). value' write data to excel
Sheet. cells (T, 5). value = Rs. Fields (5). Value 'write data to excel
Sheet. cells (T, 6). value = Rs. Fields (6). value' write data to excel
Sheet. cells (T, 7). value = Rs. Fields (7). value' write data to excel
Rs. movenext
Next
Activeworkbook. Save save
Msgbox "exported"
'Application. Visible = true' EXCEL to make it visible
Workbook. Close
Set workbook = nothing
Set sheet = nothing
Set Application = nothing
Rs. Close
Conn. Close
End if
End sub