how to search in subform by any part of content with considring spaces access
I want to search in access field.
i have used (like "*") and this gives me a good result but I want to keep searching when the user write "space" between the words in the content.
please help
ms-access
add a comment |
I want to search in access field.
i have used (like "*") and this gives me a good result but I want to keep searching when the user write "space" between the words in the content.
please help
ms-access
Could you provide an example of the search string and the data you are trying to match?
– Lee Mac
Nov 24 '18 at 11:59
add a comment |
I want to search in access field.
i have used (like "*") and this gives me a good result but I want to keep searching when the user write "space" between the words in the content.
please help
ms-access
I want to search in access field.
i have used (like "*") and this gives me a good result but I want to keep searching when the user write "space" between the words in the content.
please help
ms-access
ms-access
asked Nov 24 '18 at 11:01
M.JM.J
84
84
Could you provide an example of the search string and the data you are trying to match?
– Lee Mac
Nov 24 '18 at 11:59
add a comment |
Could you provide an example of the search string and the data you are trying to match?
– Lee Mac
Nov 24 '18 at 11:59
Could you provide an example of the search string and the data you are trying to match?
– Lee Mac
Nov 24 '18 at 11:59
Could you provide an example of the search string and the data you are trying to match?
– Lee Mac
Nov 24 '18 at 11:59
add a comment |
3 Answers
3
active
oldest
votes
Use an array:
Dim Words As Variant
Dim Word As String
Dim Index As Integer
Words = Split("Words to search", " ")
For Index = LBound(Words) To UBound(Words)
Word = Trim(Words(Index))
If Word <> "" Then
' Run your search routine using the word in Word.
End If
Next
could you please explain more
– M.J
Nov 24 '18 at 21:30
Not really - you haven't revealed your search routine. But insert it after the comment.
– Gustav
Nov 25 '18 at 9:48
add a comment |
When using a search box, I am of the opinion that additional search terms should be applied using an AND
logic so as to narrow the search, rather than broaden it (as would be obtained from OR
logic).
Hence, I would suggest something along the lines of the following:
Function SearchQuery(strFind As String) As DAO.QueryDef
Dim arrTrm() As String
Dim arrCrt() As String
Dim strCrt As String
Dim lngIdx As Long
arrTrm = Split(strFind, " ")
ReDim arrCrt(UBound(arrTrm))
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
arrCrt(lngIdx) = "par" & CStr(lngIdx)
Next lngIdx
Dim qdfQry As DAO.QueryDef
Dim rstRst As DAO.Recordset
Set SearchQuery = CurrentDb.CreateQueryDef _
( _
"", _
"select * from table1 where table1.field1 like " & _
Join(arrCrt, " and table1.field1 like ") _
)
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
SearchQuery.Parameters(lngIdx) = "*" & arrTrm(lngIdx) & "*"
Next lngIdx
End Function
The above will construct & return a parameterised unnamed query definition which is configured to search the content of field field1
of table table1
for all words supplied in the space-delimited string.
For example:
Function test()
With SearchQuery("Your Search Query").OpenRecordset
If Not .EOF Then
.MoveFirst
Do Until .EOF
Debug.Print !Field1
.MoveNext
Loop
End If
.Close
End With
End Function
Such words could appear in the field content in any order, but must all appear in the content.
This is of course but one way to accomplish this - for your particular application it is likely easier to update the SQL of a saved query, or perform some operation on the results of the query within this function, but I'll leave that for you to decide.
add a comment |
Where the user puts spaces in their search string, replace each space with " OR " before you use it to search.
so they type: "apple orange"
you add the " OR " to search for apple OR orange
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457442%2fhow-to-search-in-subform-by-any-part-of-content-with-considring-spaces-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use an array:
Dim Words As Variant
Dim Word As String
Dim Index As Integer
Words = Split("Words to search", " ")
For Index = LBound(Words) To UBound(Words)
Word = Trim(Words(Index))
If Word <> "" Then
' Run your search routine using the word in Word.
End If
Next
could you please explain more
– M.J
Nov 24 '18 at 21:30
Not really - you haven't revealed your search routine. But insert it after the comment.
– Gustav
Nov 25 '18 at 9:48
add a comment |
Use an array:
Dim Words As Variant
Dim Word As String
Dim Index As Integer
Words = Split("Words to search", " ")
For Index = LBound(Words) To UBound(Words)
Word = Trim(Words(Index))
If Word <> "" Then
' Run your search routine using the word in Word.
End If
Next
could you please explain more
– M.J
Nov 24 '18 at 21:30
Not really - you haven't revealed your search routine. But insert it after the comment.
– Gustav
Nov 25 '18 at 9:48
add a comment |
Use an array:
Dim Words As Variant
Dim Word As String
Dim Index As Integer
Words = Split("Words to search", " ")
For Index = LBound(Words) To UBound(Words)
Word = Trim(Words(Index))
If Word <> "" Then
' Run your search routine using the word in Word.
End If
Next
Use an array:
Dim Words As Variant
Dim Word As String
Dim Index As Integer
Words = Split("Words to search", " ")
For Index = LBound(Words) To UBound(Words)
Word = Trim(Words(Index))
If Word <> "" Then
' Run your search routine using the word in Word.
End If
Next
answered Nov 24 '18 at 15:34
GustavGustav
29.9k51835
29.9k51835
could you please explain more
– M.J
Nov 24 '18 at 21:30
Not really - you haven't revealed your search routine. But insert it after the comment.
– Gustav
Nov 25 '18 at 9:48
add a comment |
could you please explain more
– M.J
Nov 24 '18 at 21:30
Not really - you haven't revealed your search routine. But insert it after the comment.
– Gustav
Nov 25 '18 at 9:48
could you please explain more
– M.J
Nov 24 '18 at 21:30
could you please explain more
– M.J
Nov 24 '18 at 21:30
Not really - you haven't revealed your search routine. But insert it after the comment.
– Gustav
Nov 25 '18 at 9:48
Not really - you haven't revealed your search routine. But insert it after the comment.
– Gustav
Nov 25 '18 at 9:48
add a comment |
When using a search box, I am of the opinion that additional search terms should be applied using an AND
logic so as to narrow the search, rather than broaden it (as would be obtained from OR
logic).
Hence, I would suggest something along the lines of the following:
Function SearchQuery(strFind As String) As DAO.QueryDef
Dim arrTrm() As String
Dim arrCrt() As String
Dim strCrt As String
Dim lngIdx As Long
arrTrm = Split(strFind, " ")
ReDim arrCrt(UBound(arrTrm))
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
arrCrt(lngIdx) = "par" & CStr(lngIdx)
Next lngIdx
Dim qdfQry As DAO.QueryDef
Dim rstRst As DAO.Recordset
Set SearchQuery = CurrentDb.CreateQueryDef _
( _
"", _
"select * from table1 where table1.field1 like " & _
Join(arrCrt, " and table1.field1 like ") _
)
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
SearchQuery.Parameters(lngIdx) = "*" & arrTrm(lngIdx) & "*"
Next lngIdx
End Function
The above will construct & return a parameterised unnamed query definition which is configured to search the content of field field1
of table table1
for all words supplied in the space-delimited string.
For example:
Function test()
With SearchQuery("Your Search Query").OpenRecordset
If Not .EOF Then
.MoveFirst
Do Until .EOF
Debug.Print !Field1
.MoveNext
Loop
End If
.Close
End With
End Function
Such words could appear in the field content in any order, but must all appear in the content.
This is of course but one way to accomplish this - for your particular application it is likely easier to update the SQL of a saved query, or perform some operation on the results of the query within this function, but I'll leave that for you to decide.
add a comment |
When using a search box, I am of the opinion that additional search terms should be applied using an AND
logic so as to narrow the search, rather than broaden it (as would be obtained from OR
logic).
Hence, I would suggest something along the lines of the following:
Function SearchQuery(strFind As String) As DAO.QueryDef
Dim arrTrm() As String
Dim arrCrt() As String
Dim strCrt As String
Dim lngIdx As Long
arrTrm = Split(strFind, " ")
ReDim arrCrt(UBound(arrTrm))
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
arrCrt(lngIdx) = "par" & CStr(lngIdx)
Next lngIdx
Dim qdfQry As DAO.QueryDef
Dim rstRst As DAO.Recordset
Set SearchQuery = CurrentDb.CreateQueryDef _
( _
"", _
"select * from table1 where table1.field1 like " & _
Join(arrCrt, " and table1.field1 like ") _
)
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
SearchQuery.Parameters(lngIdx) = "*" & arrTrm(lngIdx) & "*"
Next lngIdx
End Function
The above will construct & return a parameterised unnamed query definition which is configured to search the content of field field1
of table table1
for all words supplied in the space-delimited string.
For example:
Function test()
With SearchQuery("Your Search Query").OpenRecordset
If Not .EOF Then
.MoveFirst
Do Until .EOF
Debug.Print !Field1
.MoveNext
Loop
End If
.Close
End With
End Function
Such words could appear in the field content in any order, but must all appear in the content.
This is of course but one way to accomplish this - for your particular application it is likely easier to update the SQL of a saved query, or perform some operation on the results of the query within this function, but I'll leave that for you to decide.
add a comment |
When using a search box, I am of the opinion that additional search terms should be applied using an AND
logic so as to narrow the search, rather than broaden it (as would be obtained from OR
logic).
Hence, I would suggest something along the lines of the following:
Function SearchQuery(strFind As String) As DAO.QueryDef
Dim arrTrm() As String
Dim arrCrt() As String
Dim strCrt As String
Dim lngIdx As Long
arrTrm = Split(strFind, " ")
ReDim arrCrt(UBound(arrTrm))
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
arrCrt(lngIdx) = "par" & CStr(lngIdx)
Next lngIdx
Dim qdfQry As DAO.QueryDef
Dim rstRst As DAO.Recordset
Set SearchQuery = CurrentDb.CreateQueryDef _
( _
"", _
"select * from table1 where table1.field1 like " & _
Join(arrCrt, " and table1.field1 like ") _
)
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
SearchQuery.Parameters(lngIdx) = "*" & arrTrm(lngIdx) & "*"
Next lngIdx
End Function
The above will construct & return a parameterised unnamed query definition which is configured to search the content of field field1
of table table1
for all words supplied in the space-delimited string.
For example:
Function test()
With SearchQuery("Your Search Query").OpenRecordset
If Not .EOF Then
.MoveFirst
Do Until .EOF
Debug.Print !Field1
.MoveNext
Loop
End If
.Close
End With
End Function
Such words could appear in the field content in any order, but must all appear in the content.
This is of course but one way to accomplish this - for your particular application it is likely easier to update the SQL of a saved query, or perform some operation on the results of the query within this function, but I'll leave that for you to decide.
When using a search box, I am of the opinion that additional search terms should be applied using an AND
logic so as to narrow the search, rather than broaden it (as would be obtained from OR
logic).
Hence, I would suggest something along the lines of the following:
Function SearchQuery(strFind As String) As DAO.QueryDef
Dim arrTrm() As String
Dim arrCrt() As String
Dim strCrt As String
Dim lngIdx As Long
arrTrm = Split(strFind, " ")
ReDim arrCrt(UBound(arrTrm))
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
arrCrt(lngIdx) = "par" & CStr(lngIdx)
Next lngIdx
Dim qdfQry As DAO.QueryDef
Dim rstRst As DAO.Recordset
Set SearchQuery = CurrentDb.CreateQueryDef _
( _
"", _
"select * from table1 where table1.field1 like " & _
Join(arrCrt, " and table1.field1 like ") _
)
For lngIdx = LBound(arrTrm) To UBound(arrTrm)
SearchQuery.Parameters(lngIdx) = "*" & arrTrm(lngIdx) & "*"
Next lngIdx
End Function
The above will construct & return a parameterised unnamed query definition which is configured to search the content of field field1
of table table1
for all words supplied in the space-delimited string.
For example:
Function test()
With SearchQuery("Your Search Query").OpenRecordset
If Not .EOF Then
.MoveFirst
Do Until .EOF
Debug.Print !Field1
.MoveNext
Loop
End If
.Close
End With
End Function
Such words could appear in the field content in any order, but must all appear in the content.
This is of course but one way to accomplish this - for your particular application it is likely easier to update the SQL of a saved query, or perform some operation on the results of the query within this function, but I'll leave that for you to decide.
answered Nov 24 '18 at 23:49
Lee MacLee Mac
4,37931541
4,37931541
add a comment |
add a comment |
Where the user puts spaces in their search string, replace each space with " OR " before you use it to search.
so they type: "apple orange"
you add the " OR " to search for apple OR orange
add a comment |
Where the user puts spaces in their search string, replace each space with " OR " before you use it to search.
so they type: "apple orange"
you add the " OR " to search for apple OR orange
add a comment |
Where the user puts spaces in their search string, replace each space with " OR " before you use it to search.
so they type: "apple orange"
you add the " OR " to search for apple OR orange
Where the user puts spaces in their search string, replace each space with " OR " before you use it to search.
so they type: "apple orange"
you add the " OR " to search for apple OR orange
answered Nov 26 '18 at 5:25
trevortrevor
10215
10215
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457442%2fhow-to-search-in-subform-by-any-part-of-content-with-considring-spaces-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you provide an example of the search string and the data you are trying to match?
– Lee Mac
Nov 24 '18 at 11:59