标题:execl access类型不对怎么回事?
只看楼主
sznt
Rank: 2
等 级:论坛游民
帖 子:161
专家分:20
注 册:2005-8-4
结帖率:66.67%
 问题点数:0 回复次数:5 
execl access类型不对怎么回事?
类型不对怎么回事?
Private Sub CommandButton2_Click()
Dim pf As String

pf = InputBox("请输入数据库所在盘符:")

MsgBox ("你确认盘符" & pf & " ")

     Sheets("Sheet2").Select
   
   If a1 = "" Then
     Sheets("sheet2").Range("A1:i20000").Select
     Selection.ClearContents
    'Selection.QueryTable.Delete
     Sheets("sheet2").Range("i20000").Select
     
   Sheets("sheet2").Range("A1").Select

  Else
  
     Sheets("sheet2").Range("A1:i20000").Select
     Selection.ClearContents
    Selection.QueryTable.Delete
     Sheets("sheet2").Range("i20000").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"))
      [bo]从这句开始  .CommandText = Array( _
    "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")
  到这段说类型不对,不知为何?[/bo]

.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

Sheets("FFF").Select

End Sub
搜索更多相关主题的帖子: execl access 数据库 Range 
2008-05-03 08:23
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 
我觉得CommandText应该是个String,内容是SQL语句,而你赋的是个数组。你在哪里看到类似代码的?
2008-05-03 08:46
sznt
Rank: 2
等 级:论坛游民
帖 子:161
专家分:20
注 册:2005-8-4
得分:0 
忘记在哪里看到了,很早做的,连原来的access就没事,换成这个不知为何出错,要如何改呢?好着急。
2008-05-03 08:49
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"

你笑我和你们不一样,我笑你们大家都一样~
2008-05-03 11:12
sznt
Rank: 2
等 级:论坛游民
帖 子:161
专家分:20
注 册:2005-8-4
得分:0 
按楼上操作,出现以下情况
.Refresh BackgroundQuery:=False出现odbc一般错误
2008-05-03 12:14
sznt
Rank: 2
等 级:论坛游民
帖 子:161
专家分:20
注 册:2005-8-4
得分:0 
感谢wangtuan7788兄,问题圆满解决,谢谢。
2008-05-03 13:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-212108-1-1.html




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

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