| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 869 人关注过本帖
标题:access数据导入execl时不按设定主键排序?
只看楼主 加入收藏
sznt
Rank: 2
等 级:论坛游民
帖 子:161
专家分:20
注 册:2005-8-4
结帖率:66.67%
收藏
 问题点数:0 回复次数:2 
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
搜索更多相关主题的帖子: execl access 数据 
2008-05-03 21:00
wangtuan7788
Rank: 1
等 级:新手上路
帖 子:286
专家分:0
注 册:2007-10-8
收藏
得分:0 
.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 order by drv_temp_mid.编号"

你笑我和你们不一样,我笑你们大家都一样~
2008-05-03 22:18
sznt
Rank: 2
等 级:论坛游民
帖 子:161
专家分:20
注 册:2005-8-4
收藏
得分:0 
[bo]以下是引用 [un]wangtuan7788[/un] 在 2008-5-3 22:18 的发言:[/bo]

.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, dr ...

谢谢,问题解决,希望以后能够再次得到帮助支持。
2008-05-04 07:06
快速回复:access数据导入execl时不按设定主键排序?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035709 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved