Private Sub Command1_Click()
Dim strQuery As String
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
d1 = Trim(Text1.Text)
d2 = Trim(Text2.Text)
Adodc1.CommandType = adCmdText
If Option1.Value = True Then
   strQuery = "select * from 论文成果  and 发表时间>='" & d1 & "' And 发表时间<= '" & d2 & "'"
End If
If Option2.Value = True Then
   strQuery = "select * from 论文成果 where 论文题目='" & Trim(Text3.Text) & "'"
End IfIf Option3.Value Then
   strQuery = "select * from 论文成果 where 教师姓名='" & Trim(Text3.Text) & "'"
End If
Adodc1.RecordSource = strQuery
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "不存在此记录!"
End IfEnd Sub
教师姓名和论文题目查询正常,只是时间查询有问题,如果改成20050505这样的话就可以了,日期格式就不行了……
查询好像还要转化数据类型,怎么弄呢?  如果改用DTPicker控件呢?
程序运行先报 FROM 子句语法错误 ,之后弹出vb 对象refresh的方法 iadodc失败
我想实现的是论文的日期区间查询,就是输入2005/5/1 和2011/5/1后中间的数据显示出来。多谢多谢了!!
老师还要求我把查询结果输出,我也不会弄,那位大哥知道请指条明路!!
以下附全部程序
Private Sub Command1_Click()
Dim strQuery As String
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
d1 = Trim(Text1.Text)
d2 = Trim(Text2.Text)
Adodc1.CommandType = adCmdText
If Option1.Value = True Then
   strQuery = "select * from 论文成果  and 发表时间>='" & d1 & "' And 发表时间<= '" & d2 & "'"
End If
If Option2.Value = True Then
   strQuery = "select * from 论文成果 where 论文题目='" & Trim(Text3.Text) & "'"
End IfIf Option3.Value Then
   strQuery = "select * from 论文成果 where 教师姓名='" & Trim(Text3.Text) & "'"
End If
Adodc1.RecordSource = strQuery
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "不存在此记录!"
End IfEnd SubPrivate Sub Command2_Click()
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
End SubPrivate Sub Command3_Click()
Unload Me
主界面.Show
End SubPrivate Sub Command4_Click()
Dim SQLstr As String  SQLstr = "select * from 论文成果 "
 Adodc1.RecordSource = SQLstr
 Adodc1.Refresh
 Adodc1.Refresh
 
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\教师业绩.mdb;Persist Security Info=False"
Adodc1.RecordSource = "论文成果"
Adodc1.Refresh
End SubPrivate Sub Option1_Click()
Frame3.Visible = True
Frame4.Visible = False
End SubPrivate Sub Option2_Click()
Frame3.Visible = False
Frame4.Visible = True
End SubPrivate Sub Option3_Click()
Frame3.Visible = False
Frame4.Visible = True
End Sub

解决方案 »

  1.   

    发表时间字段:
    strQuery = "select * from 论文成果 and 发表时间 between#" & d1 & "# And #" & d2 & "#"
      

  2.   


    strQuery = "select * from 论文成果 and 发表时间 between #" & d1 & "# And #" & d2 & "#"
      

  3.   

    'and改为where
    strQuery = "select * from 论文成果 where 发表时间 between #" & d1 & "# And #" & d2 & "#"
      

  4.   

    多谢二位大大了!!因为这里新回复不提示,所以没有及时看到你们的回复,搞的自己也纠结了几天,在此感谢!!
    http://zhidao.baidu.com/question/273368728.html
    请在百度也回复下,那里的分也给你们吧,回复加CSDN
      

  5.   

    如果可以帮我看一下另外的一个我的问题,地址是  http://zhidao.baidu.com/question/274366544.html