数据库字段中recdate存日期  rectime存时间 
DTPicker1中选择日期  combol1中存了1到24用来选择时间hour类型定义
Dim strSql As String
Dim myDate
Dim myTime, myTime1
Dim day
Dim month
Dim year
Dim hour
Dim  myDb As Database
Dim  myRs As Recordset
Dim sPath As Stringday = Trim(DTPicker1.day)
 month = Trim(DTPicker1.month)
 year = Trim(DTPicker1.year) myDate = CStr(year) + "-" + CStr(month) + "-" + CStr(day) + "'"      myTime1 =  "recTime" & ">'" & Format(CDate(CStr(hour) & ":00:00"), "hh:mm:ss")   & "'" & " and " & "recTime<'" & Format(CDate(CStr(hour) & ":59:59"), "hh:mm:ss")  & "' order by recTime" 
 '表示hour:00:00到hour:59:59sPath = App.Path & "\wsdata.mdb"  'access数据库wsdata.mdb
strSql = "select * FROM tabel1 where recDate ='" & myDate & " and " & myTime1
Set myDb = OpenDatabase(sPath)
Set myRs = myDb.OpenRecordset(strSql)  '''在此出错 说是类型不匹配
在access中定义的recdate 和rectime是日期时间型
为什么会出这样的错误啊
正在学习中 请大家不吝赐教!!!谢谢各位

解决方案 »

  1.   

    还有问题是 我只要把access中的定义成文本就不出错了,
    可是因为实际后续需要 必须得是时间日期格式 否则按order by recdate,rectime排列出来的就不是按时间顺序排列了
      

  2.   

    谢谢clear_zero照你的意见我改了 如下:(还是出错)
    Dim myRs As New adodb.Recordset
    Dim conn As New adodb.Connection
    sPath = App.Path & "\wsdata.mdb"
    strSql = "select * FROM tabel1 where recDate ='" & myDate & " and " & myTime1
    Set myDb = OpenDatabase(sPath)
     If conn.State = adStateOpen Then conn.Close
    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & sPath & " ';Persist  Security Info=False"
    myRs.CursorLocation = adUseClient
    myRs.Open strSql, conn    '''出错 标准表达式中数据类型出错