Dim cn as the new ADODB. relationship
Dim rs as the new ADODB. Record set
Display sql as a string
cn.open "provider=Microsoft。 Jet. OLEDB.4.0 data source = "&app. Path and path. "/data/goodStock.mdb "
sql = " select * from " & ampList 1。 Text & ""
rs。 Source = sql
Set rs. ActiveConnection = cn
rs。 LockType = adLockOptimistic
rs。 CursorLocation = adUseClient
rs.open sql,cn
Mark I as an integer
Dim j is an integer
Dim xlExcel to the new Excel. app; application
Adjust xlBook to Excel. exercise book
Adjust xlSheet to Excel format. worksheet
Set xlBook = xlExcel. Workbooks. Adding
Set xlSheet = xlExcel. Worksheet. Add
If rs. Record Count & lt Then 1
MsgBox "data not exported", vbOKOnly+vbCritical, "error prompt"
outlet connection
other
-Save dialog-
Using CommonDialog2
. InitDir = App。 Path sets the initial path when CommonDialog 1 is opened as the current program path.
. Filter = "Excel (*。 xls)|*。 Xls| "'sets its filtering attribute to xls files, that is, only the xls files in this folder are displayed.
. CancelError = True' If you click Cancel, you don't need to report an error, just skip.
. DialogTitle = "Export database"' Save the dialog box title.
. Show Save pops up the Save dialog box.
End with ...
If ... it will be over.
-Modify the worksheet name and add a box to the table-
XlBook。 ActiveSheet.name = "test export data"
Xlsheet。 Cells. Column (10). Increase the array width.
Xlsheet.cells ( 1, 1) = "Test 1 "
XlSheet。 Cell (1, 2) = "Test 2"
XlSheet。 Cell (1, 3) = "Test 3"
XlSheet。 Cell (1, 4) = "Test 4"
XlSheet。 Cell (1, 5) = "Test 5"
XlSheet。 Cell (1, 6) = "Test 6"
XlSheet。 Cell (1, 7) = "Test 7"
XlSheet。 Cell (1, 8) = "Test 8"
XlSheet。 Cell (1, 9) = "Test 9"
Xlsheet.cells ( 1, 10) = "Test 10 "
For i = 2 to rs. Record Count+1
For j = 1 to rs. Field. count
xlSheet。 Cells(i,j) = rs。 Project (j-1). value
Next J.
rs。 next step
Next, I
if common dialog 2 . filename & lt; & gt ""So
Xlbook。 "saveascommondialog2.filename" saves data.
ElseIf CommonDialog2.filename = ""Then
outlet connection
other
If exist = False, MsgBox "has no data table to back up!" , vbOKOnly, "attention"
If ... it will be over.
Set xlSheet = Nothing' publish
Set xlBook = Nothing' publish
XlExcel。 Exit "Close Microsoft Excel by Exit Method" to release the object.
Set xlExcel = Nothing' publishing
MsgBox "Test export data succeeded", 0+48, "Information prompt!"
Rs off
Cn. close
End joint