如果是SQL的话就可以用存储过程了,Access是不支持这样的。考虑一下SQL的存储过程吧。然后用下面的语句调用: dim myconn as new adodb.connection dim myrs as new adodb.recordset myconn.connectionstring=yourconnstring querystring="Exec myproc '" & txtname.text & "','" & txttime.text & "'" set myrs=mydb.execute(querystring) 这样就可以实现你的代参数查询的要求了。而且执行效率高了许多。
对于这样一个查询 Select * From 表名 Where 字段名=变量名 的参查询 在vb中可以使用Adodb.command 和 adodb.P**** 两个对象进行.在msdn中有 详细的解决示例。具体的代码可参照示例.
access中的VBA功能比较弱,完成不了这样的操作。
Dim rs As New ADODB.Recordsetrs.open"SELECT * FROM 表名 WHERE 人名='"+trim(txtRm)+"'" and 时间='"+trim(txtSj)+"'...... 即可!
用" & 变量名 & "引用变量,如果是字符型,请在前后加'(单引号),
dim AdoCx as adodb.recordset set adocx=new adodb.recordset adocx.open" select * from 表名 where 姓名 like '"+trim(text.text)+"%' and format(时间,"yyyy-mmm-dd")='"+format(trim(时间控件),yyyy-mm-dd)+"'.............
Dim rs As New ADODB.Recordsetrs.Open "select * from 人名 = '" & txtName.Text & "' and 时间 = #" & textTime.Text & "#"
然后Dim rs As New ADODB.Recordsetrs.Open "select * from 人名 = '" & txtName.Text & "' and 时间 = #" & txtTime.Text & "#"
dim myconn as new adodb.connection
dim myrs as new adodb.recordset
myconn.connectionstring=yourconnstring
querystring="Exec myproc '" & txtname.text & "','" & txttime.text & "'"
set myrs=mydb.execute(querystring)
这样就可以实现你的代参数查询的要求了。而且执行效率高了许多。
在vb中可以使用Adodb.command 和 adodb.P**** 两个对象进行.在msdn中有
详细的解决示例。具体的代码可参照示例.
and 时间='"+trim(txtSj)+"'...... 即可!
set adocx=new adodb.recordset
adocx.open" select * from 表名 where 姓名 like '"+trim(text.text)+"%' and
format(时间,"yyyy-mmm-dd")='"+format(trim(时间控件),yyyy-mm-dd)+"'.............