|
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 & "*' "这句去掉,则可以工作。问题是:这样我只能进行整个表数据的复制,无法设置条件。请教如何解决?
|
|