`Option Compare Database
Option Explicit
Dim argcount As Integer
Dim mysql As String, msg As String, mysource As String, mycriteria As String, mysource1 As String, mysql1 As String
Private Sub AddtoWhere(FieldValue As Variant, FieldName As String, mycriteria As String, argcount As Integer)
' Create criteria for WHERE clause.
If FieldValue <> "" Then
' Add "and" if other criterion exists.
If argcount > 0 Then
mycriteria = mycriteria & " and "
End If
' Append criterion to existing criteria.
' Enclose FieldValue and asterisk in quotation marks.
mycriteria = (mycriteria & FieldName & " Like " & Chr(34) & FieldValue & Chr(42) & Chr(34))
' Increase argument count.
argcount = argcount + 1
End If
End Sub
Private Sub Search_Click()
Dim Search As String
here:
argcount = 0
' Initialize SELECT statement.
mysql = "SELECT * FROM tbltab WHERE "
mycriteria = ""
mysql1 = "SELECT * FROM tblTemp WHERE "
mycriteria = ""
' Use values entered in text boxes in form header to create criteria for WHERE clause.
AddtoWhere cboProduct, "ABC1", mycriteria, argcount
AddtoWhere cboSource, "ABC2", mycriteria, argcount
AddtoWhere cboPType, "ABC3", mycriteria, argcount
'If no criterion specifed, stop the search.
'you'll be glad you did if there are thousands of Persons maybe.
If mycriteria = "" Then
mycriteria = True
End If
' Create SELECT statement.
mysource = mysql & mycriteria
mysource1 = mysql1 & mycriteria
Dim strval As String
'set the recordsource of the subform to the resultset
Me!sfrmCap.Form.RecordSource = mysource
Me!sfrmCapTemp.Form.RecordSource = mysource1
Exit_cmdsearch_Click:
Exit Sub
Err_cmdsearch_Click:
DoCmd.Hourglass False
DoCmd.Echo True
MsgBox Err.Description & " Person Search Command Cancelled", vbInformation, "Person Search Command Cancelled"
Resume Exit_cmdsearch_Click
End Sub
`我有一個窗體中有2個子窗體。我有一個搜索按鈕,當點擊搜索記錄時使用組合框的值,但在一個組合框中,它顯示的只是相關的記錄,而不是完整的搜索。女士訪問形式 - 如何使用搜索按鈕完全過濾文本
任何人都可以幫助我。
謝謝。
「[...]在一個組合框中顯示的只是相關的記錄而不是完整的搜索。」 - 我不明白這是什麼意思。我認爲組合框被用來爲搜索提供輸入參數,但是這聽起來好像他們應該顯示搜索結果一樣。你能詳細說明嗎? – Leviathan
對不起,如果我沒有解釋清楚,組合框用於選擇值或文本,然後文本應該用於過濾下面的數據表。組合框爲搜索提供輸入參數。正如你在圖片中看到的,它沒有顯示完整的結果,而是顯示相關的記錄,我希望它應該搜索完整的文本。 – Beginner
由一個組合框我的意思是,你可以看到圖像我有5個組合框,其餘工作正常,它只是源組合框不能正常工作,我無法找出問題。 – Beginner