Office中国论坛/Access中国论坛

标题: SQL语句 [打印本页]

作者: horoscope    时间: 2003-1-9 00:08
标题: SQL语句
Private Sub cmdsearch_Click()
Dim DB As New ADODB
Set DB = CurrentProject.Connection
Dim strtj As String
strtj = " SELECT tblsupplier.SupplierID, tblsupplier.SupplierName, tblsupplier.Address, tblsupplier.Postal, tblsupplier.Tel, tblsupplier.Fax, tblsupplier.BP, tblsupplier.Email, tblsupplier.Contact, tblsupplier.message INTO tbltemp FROM tblsupplier"
strtj = strtj & "where SupplierID like '*" & txt供应商_ID & "*' "
MsgBox strtj
'Set DB = CurrentProject.Connection
'DB.Execute strtj
'strtj1 = "INSERT INTO tblsuppliertemp SELECT * FROM tbltemp"
'DB.Execute strtj1
'frmsupplier_sub.Requery
Dim cmd As Command
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = CurrentProject.Connection
.CommandType = adCmdText
.CommandText = strtj '
End With

Dim rs As Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open "tbltemp", , adOpenKeyset, adLockBatchOptimistic, adCmdTable
Set rs = Nothing
DoCmd.SelectObject acTable, "tbltemp", True
DoCmd.OpenTable "tbltemp", acViewNormal, acReadOnly
Set DB = Nothing
'frmsupplier_sub.Requery
End Sub
完成以上程序,应该在生成符合条件的表,但执行后,却什么也没增加。
若把strtj = strtj & "where SupplierID like '*" & txt供应商_ID & "*' "这句去掉,则可以工作。问题是:这样我只能进行整个表数据的复制,无法设置条件。请教如何解决?

作者: 九阳先生    时间: 2003-1-9 04:55
将strtj = strtj & "where SupplierID like '*" & txt供应商_ID & "*' "
改为 strtj = strtj & " where SupplierID like '*" & txt供应商_ID & "*' "
即在where之前加一个空格试试


作者: horoscope    时间: 2003-1-9 16:52
问题已经解决,在ADO 中LIKE不支持”*“的模糊查询,改用”%“即可。

作者: eio    时间: 2003-1-9 17:12
例子呢




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3