Private Sub Command5_Click()
Dim rst As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim MyDate As Date
Dim sql As String
Dim startdate As String
Dim enddate As Stringstartdate = Year(DTPicker1.Value) & "/" & Month(DTPicker1.Value) & "/" & Day(DTPicker1.Value) & " 00:00:01"
enddate = Year(DTPicker1.Value) & "/" & Month(DTPicker1.Value) & "/" & Day(DTPicker1.Value) & " 23:59:59"Set con = New ADODB.Connection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=prdinfo9797.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
con.Opensql = " select ID,opr,recddate,PrdNo,Construction,Spec,YarnCount,Content,Shrink,Color,flexible,Wgtbfwsh,Wgtafwsh,Width,WidthCutable,PcOrYarnDye,currentstock,CareInstr from prdinfo where prdinfo!recddate  Between #" & startdate & "# And #" & enddate & "#"
sql = sql & " order by custinfo.recddate"
  If Check1.Value = 1 Then
   sql = sql & "order by custinfo.prdno"
      ElseIf Check2.Value = 1 Then
       sql = sql & "order by custinfo.color"
         ElseIf Check3.Value = 1 Then
          sql = slq & "order by custinfo.wghafwsh "
           ElseIf Check4.Value = 1 Then
            sql = sql & "group by custinfo.flexible"
           ElseIf Check5.Value = 1 Then
           sql = sql & "order by custinfo.width"
         End If
            
        
        
Set rst = con.Execute(sql)
s = rst.Fields.Count
If rst.BOF = True Then
    MsgBox "在您输入日期内为输入客户资料记录!", 48, "警告"
   
Else
Set DataGrid1.DataSource = rst
    For i = 0 To s - 1
        DataGrid1.Columns(i).Alignment = dbgCenter
        DataGrid1.Columns(i).Width = 1000
    Next i
    
End IfEnd Sub

解决方案 »

  1.   

    估计是SQL语句问题
    你在Set rst = con.Execute(sql)前加一句debug.print sql看看你的SQL语句有没有问题,拷贝到查询分析器中能不能执行
      

  2.   

    from prdinfo where prdinfo!recddate  Between #" & startdate & "# And #" & enddate & "#"
    ------------------
    prdinfo!recddate  修改为prdinfo.recddate
      

  3.   

    还有问题,在sql = sql & " order by custinfo.recddate"这句以后又用CheckBox来判断排序,这样有二个order by子句了吧?肯定不对了
      

  4.   

    1. AS VBMAN SAID, CNT BE ORDERED BY TWO DIFFERENT CONDITIONS
    2. SPELLING MISTAKE, OR RESERVED WORD SHOULD HAV [ID]