Private Sub DataRefresh()
  Dim TmpSource As String
  Dim StrSch As String
  Dim StrDate As String
  '设置查询条件
  '判断是否选中“全部”,如果没有则提取不同的查询条件
  If Check1.Value = 1 Then
    StrSch = ""
  Else
    If cob_Flag.ListIndex > 0 Then
      StrSch = " And l.Flag=" + Trim(cob_Flag.ListIndex)
    End If
    If Len(Trim(dco_Type.Text())) > 0 Then
      StrSch = StrSch + " And l.TypeId=" + dco_Type.BoundText()
    End If
    If Len(Trim(cob_Date.Text)) > 0 Then
      StrDate = Format(cob_Date.Text, "yyyy-mm-dd")
      StrSch = " AND l.UseDate='" + Trim(StrDate) + "'"
    End If
  End If
  TmpSource = "Select l.Id, IIF(l.Flag=0,'收入','支出') AS 收支类型," _
     + "t.TypeName AS 分类名称,l.ANo AS 账号,l.UseDate AS 收支日期," _
     + "l.UseSum AS 收支金额,m.MemName AS 使用人,l.Memos AS 说明,l.Flag " _
     + " From InOutList l,Types t,Members m " _
     + " Where l.MemId=m.MemId And l.TypeId=t.TypeId" + StrSch _
     + " Order By l.UseDate Desc"
'MsgBox TmpSource
  Adodc1.ConnectionString = Conn
  Adodc1.RecordSource = TmpSource
  Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1
  DataGrid1.Columns(0).Width = 0  '编号
  DataGrid1.Columns(1).Width = 2100  '收支类型
  DataGrid1.Columns(2).Width = 1000  '分类名称
  DataGrid1.Columns(3).Width = 1600  '账号
  DataGrid1.Columns(4).Width = 1000  '收支日期
  DataGrid1.Columns(5).Width = 1200  '收支金额
  DataGrid1.Columns(6).Width = 1000  '使用人
  DataGrid1.Columns(7).Width = 1200  '说明
   DataGrid1.Columns(8).Width = 0 'Flag
 
End Sub 

解决方案 »

  1.   

    + " Where l.MemId=m.MemId And l.TypeId=t.TypeId " + StrSch _t.TypeId后加个空格试一下。
      

  2.   

    此类问题可以将需要执行的SQL 语句Debug.print 出来放到查询分析器中执行一下就能查出什么问题了。
      

  3.   

      + " Where l.MemId=m.MemId And l.TypeId=t.TypeId " + StrSch _
      

  4.   

    1楼大哥,加空格也不行啊.调试后错误指到 Adodc1.Refresh 这里
    2楼大哥,我放到查询分析器中执行了,也说附近语法错误 不知道哪错了啊