access数据导入execl时不按设定主键排序?
在execl里用vba导入access数据时,不按access里设定主键的排序顺序排序,不知为何?急求解答,数据太混乱了!!!!!谢谢。
vba代码如下:
Dim pf As String
pf = InputBox("请输入数据库所在盘符:")
MsgBox ("你确认盘符" & pf & " ")
Sheets("Sheet2").Select
If a1 = "" Then
Sheets("sheet2").Range("A1:m20000").Select
Selection.ClearContents
'Selection.QueryTable.Delete
Sheets("sheet2").Range("m20000").Select
Sheets("sheet2").Range("A1").Select
Else
Sheets("sheet2").Range("A1:m20000").Select
Selection.ClearContents
Selection.QueryTable.Delete
Sheets("sheet2").Range("m20000").Select
Sheets("sheet2").Range("A1").Select
End If
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=" & pf & ":\aaa\JXBMXT.mdb;DefaultDir=" & pf & ":\aaa;DriverId=25;FIL=MS Access;MaxBufferSize=2048ageTimeou" _
), Array("t=5;")), Destination:=Sheets("sheet2").Range("A1"))
.CommandText = "SELECT drv_temp_mid.编号, drv_temp_mid.XM, drv_temp_mid.xb, drv_temp_mid.SFZMHM, drv_temp_mid.ZKCX, drv_temp_mid.DJZSXXDZ,drv_temp_mid.备注,drv_temp_mid.LXDH, drv_temp_mid.LXZSYZBM, drv_temp_mid.LXZSXXDZ, drv_temp_mid.SG, drv_temp_mid.ZSL, drv_temp_mid.YSL, drv_temp_mid.TL" & Chr(13) & "" & Chr(10) & "FROM `" & pf & ":\aaa\JXBMXT`.drv_temp_mid drv_temp_mid"
.Name = "查询来自 MS Access Database"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = True
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With