如何同时查询两个表中的内容
如下,drawingnumber在表WSPdrawing和表instore中都有(drawingnumbe为列名),现要在Text1.Text中输入一个值A,点击Command1,两表中的A都能搜索出来,帮忙看看rs.Open "select * from WSPdrawing union select * from instore where " & Trim(sql), cn, adOpenDynamic 错在哪里(现在只能筛选表instore中的A,表WSPdrawing中的内容全部显示) Private Sub Command1_Click()
sql = "drawingnumber='" & Trim(Text1.Text) & "'"
Call insearch(sql)
End Sub
Private Sub Form_Load()
sql = ""
Call insearch(sql)
Private Sub insearch(ByVal sql As String)
Set cn = New Connection
cn.CursorLocation = adUseClient
cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\jxc.mdb;"
Set rs = New adodb.Recordsetrs.
LockType = adLockOptimistic
If Len(Trim(sql)) <= 0 Then
rs.Open "select * from instore union select * from instore ", cn, adOpenDynamicElse
rs.Open "select * from WSPdrawing union select * from instore where " & Trim(sql), cn, adOpenDynamic
End If
Set DataGrid1.DataSource = rs
End Sub