|
5金钱
下面是由access数据库导出到EXCEL中的代码,但是现在有一个问题:无法按照字段名(ID)进行排序使导出数据按照ID进行排序,请大家帮助 谢谢
- Private Sub Combo11_AfterUpdate()
- Me.Combo13 = ""
- Me.Combo13.Requery
- End Sub
- Private Sub ToParts_Click()
- If IsNull(Me.Combo11) Or Me.Combo11 = "" Then
- MsgBox "请选择Team!", vbCritical
- Me.Combo11.SetFocus
- Exit Sub
- End If
- If IsNull(Me.Combo13) Or Me.Combo13 = "" Then
- MsgBox "请选择MPSDATE!", vbCritical
- Me.Combo13.SetFocus
- Exit Sub
- End If
- Dim msgTmp As VbMsgBoxResult
- msgTmp = MsgBox("确定要导出吗?", vbQuestion + vbYesNo, "Print")
- If msgTmp <> vbYes Then Exit Sub
- Dim i As Long
- Dim c, d As String
- Dim xlsAPP As Excel.Application
- Dim xlsBook As Excel.Workbook
- Dim xlsSheet As Excel.Worksheet
- Set xlsAPP = CreateObject("Excel.Application")
- xlsAPP.Visible = True
- Dim cur_r As Long
- Dim dbs As Database
- Dim Rst1 As Recordset
- Dim strSQL As String
- c = Me.Combo11
- d = Me.Combo13
- Set dbs = CurrentDb
- Set Rst1 = dbs.OpenRecordset("SELECT PaiChan_REMOTE.* FROM PaiChan_REMOTE WHERE (((PaiChan_REMOTE.Team)='" & c & "') AND ((PaiChan_REMOTE.Release_Date)=# " & d & " #)) order by PaiChan_REMOTE.RQST;")
- Set xlsBook = xlsAPP.Workbooks.OPEN("D:\散件生产计划系统\PaiChanforPI.XLT")
- Set xlsSheet = xlsBook.Worksheets("PAICHAN")
- xlsSheet.Activate
- cur_r = 4
- If Rst1.EOF = False Then
- xlsSheet.Cells(1, 1) = Rst1!Team
- Rst1.MoveFirst
- For i = 1 To Rst1.RecordCount
- cur_r = cur_r + 1
- xlsSheet.Cells(cur_r, 1) = Rst1!CUST_CLAS71
- 'xlsSheet.Cells(cur_r, 2) = Rst1!Remark
- xlsSheet.Cells(cur_r, 2) = Rst1!id
- xlsSheet.Cells(cur_r, 3) = Rst1!CO_NO
- xlsSheet.Cells(cur_r, 4) = Rst1!Line_No
- xlsSheet.Cells(cur_r, 5) = Rst1!CO_Item
- xlsSheet.Cells(cur_r, 6) = Rst1!QTY
- xlsSheet.Cells(cur_r, 7) = Rst1!Serial_No
- xlsSheet.Cells(cur_r, 8) = Rst1!Desc
- xlsSheet.Cells(cur_r, 9) = Rst1!RQST '
- xlsSheet.Cells(cur_r, 10) = Rst1!CustAkDt
- xlsSheet.Cells(cur_r, 12) = Rst1!Info11
- xlsSheet.Cells(1, 12) = Rst1!Release_Date
- '........后面自已加
- '画格子
- With xlsSheet.Range(xlsSheet.Cells(cur_r, 1), xlsSheet.Cells(cur_r, 12)).Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .Weight = xlThin
- .ColorIndex = xlAutomatic
- End With
- With xlsSheet.Range(xlsSheet.Cells(cur_r, 1), xlsSheet.Cells(cur_r, 12)).Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .Weight = xlThin
- .ColorIndex = xlAutomatic
- End With
- With xlsSheet.Range(xlsSheet.Cells(cur_r, 1), xlsSheet.Cells(cur_r, 12)).Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .Weight = xlThin
- .ColorIndex = xlAutomatic
- End With
- With xlsSheet.Range(xlsSheet.Cells(cur_r, 1), xlsSheet.Cells(cur_r, 12)).Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .Weight = xlThin
- .ColorIndex = xlAutomatic
- End With
- With xlsSheet.Range(xlsSheet.Cells(cur_r, 1), xlsSheet.Cells(cur_r, 12)).Borders(xlInsideVertical)
- .LineStyle = xlContinuous
- .Weight = xlThin
- .ColorIndex = xlAutomatic
- End With
- Rst1.MoveNext
- Next i
- End If
- Exit_cmdxls_Click:
- Exit Sub
- Err_cmdxls_Click:
- MsgBox err.Description
- Resume Exit_cmdxls_Click
- End Sub
复制代码
|
最佳答案
查看完整内容
把这句:
38.Set Rst1 = dbs.OpenRecordset("SELECT PaiChan_REMOTE.* FROM PaiChan_REMOTE WHERE (((PaiChan_REMOTE.Team)='" & c & "') AND ((PaiChan_REMOTE.Release_Date)=# " & d & " #)) order by PaiChan_REMOTE.RQST;")
改成:
38.Set Rst1 = dbs.OpenRecordset("SELECT * FROM PaiChan_REMOTE WHERE Team='" & c & "' AND Release_Date=# " & d & " # order by ID")
|