一段代码,用于查询日期数据,执行后会出现“编译错误,子程序或者函数没有定义”,而其它查询都可以。这是为什么??求救!Private Sub cmdDate_Click()
  Dim sql As String
  Dim date1 As String
  Dim date2 As String
  If Trim(txtYear(0).Text) = "" Or Trim(txtYear(1).Text) = "" Then
        MsgBox " 请填写年份!"
        Exit Sub
  End If
  If Trim(Combo1(0).Text) = "" Or Trim(Combo1(1).Text) = "" Then
        MsgBox "请填写月份!"
        Exit Sub
  End If
  If Trim(Combo2(0).Text) = "" Or Trim(Combo2(1).Text) = "" Then
        MsgBox "请填写日期!"
        Exit Sub
  End If
  date1 = Trim(txtYear(0).Text) & "-" & Trim(Combo1(0).Text) & "-" & Trim(Combo2(0).Text)
  date2 = Trim(txtYear(1).Text) & "-" & Trim(Combo1(1).Text) & "-" & Trim(Combo2(1).Text)
  sql = "select * from bill where regdate<'" & date2 & "' and regdate>'" & date1 & "' order by -noid"
  Adodc1.RecordSource = sql
  Adodc1.Refresh
End Sub

解决方案 »

  1.   

    日期前后加#号
    sql = "select * from bill where regdate<#" & cdate(date2) & "# and regdate>#" & cdate(date1) & "# order by -noid"
      

  2.   

    若是access数据库的话用楼上的代码试试
      

  3.   

    Combo1(0).Text出现问题,用的是Acess数据库
      

  4.   

    date1 = Trim(txtYear(0).Text) & "-" & Trim(Combo1(0).Text) & "-" & Trim(Combo2(0).Text)我估计这句话应该是这样的:  date1 = Trim(txtYear(0).Text) & "-" & Trim(Combo1(0).Text) & "-" & Trim(Combo1(1).Text)
      

  5.   

    如果你确认combo1(0)存在的话,我就不知道问题在哪儿了。