我想从EXCEL表中读出数据,处理后写入ACCESS中,用了一下命令。结果系统报错:语句没有结束!定位在event上面。
Set excelR = New ADODB.Recordset
excelR.Open "select EvCd,CseCd from sheet1$ where recordType="event"", xConnection, adOpenStatic, adLockBatchOptimistic我想这应该是一个语法问题,可不知改如何改?
请教各位大侠!

解决方案 »

  1.   

    cn.ConnectionString = "DRIVER={Microsoft EXCEL Driver (*.xls)};DBQ=Excel文件路径;Extended Properties=EXCEL 8.0"
    cn.CursorLocation = adUseClient
    cn.Openrs.Open "select * from [sheet1$] where 条件...", cn, adOpenDynamic, adLockOptimistic
      

  2.   

    Private Sub cmdReadXLS_Click()
          Set dgData.DataSource = Read_Excel(App.Path & "\" & "test.xls")
          Set obj = Nothing
    End SubPublic Function Read_Excel _
             (ByVal sFile _
              As String) As ADODB.Recordset      On Error GoTo fix_err
          Dim rs As ADODB.Recordset
          Set rs = New ADODB.Recordset
          Dim sconn As String      rs.CursorLocation = adUseClient
          rs.CursorType = adOpenKeyset
          rs.LockType = adLockBatchOptimistic      sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile
          rs.Open "SELECT * FROM [sheet1$]", sconn
          Set Read_Excel = rs
          Set rs = Nothing
          Exit Function
    fix_err:
          Debug.Print Err.Description + " " + _
                      Err.Source, vbCritical, "Import"
          Err.Clear
    End Function