MS Access 2010. I am using a split form and when I perform a search for a record, and there are no duplicates, need to display that single record and not the other records in the table. If are two or more records (duplicates), need to display only those duplicates and not other records in the table.
Display single record or duplicate records
Collapse
X
-
Tags: None
-
-
mcervenka1,
Welcome to Bytes!
Please review these guidelines for Asking Good Questions. Feel free to modify your question or clarify the exact problem you are having, and we will be glad to look into assisting you.
Thanks for your understanding.Comment
-
MS Access 2010. I am using a split form with search capability. When I search for a record using a specific search criteria (such as a name), I would like to display only the record and any duplicates of that record found and not the rest of the records in the table. The split form displays the rows of records in table (table format) at the bottom of the screen and displays the individual record found from search at the top half of the screen. In the rows of records at the bottom of the screen, I only want to display the record or its duplicate records found in the search.Comment
-
You should be able to apply a filter directly to the Form, based upon your Search Criteria. Example:
Code:Private Sub txtSearch_AfterUpdate() On Error GoTo EH Dim strFilter As String strFilter = "[FieldName] Like '" & Me.txtSearch & "*'" Me.Filter = strFilter Me.FilterOn = True Exit Sub EH: MsgBox "There was an error filtering the Form!" & _ vbCrLf & vbCrLf & _ Err.Number & vbCrLf & _ Err.Description & vbCrLf & vbCrLf & _ "Please contact your Database Administrator.", _ vbCritical, "WARNING!" Exit Sub End Sub
Hope this hepps!Comment
-
Twinnyfo. The coding works excellent. However, I get the parameter query value popup after I enter my criteria in the search field.
"Enter Parameter Value"
FormsInquiryRec ord!Text259Comment
-
-
this is what is in the Filter field on the form property sheet. I am using the ANumber to filter
Code:[ReceiptNumber] Like "*" & Forms![Inquiry Record]!Text259 & "*" Or [ANumber] Like "*" & Forms![Inquiry Record]!Text259 & "*" Or [SerialNumber] Like "*" & Forms![Inquiry Record]!Text259 & "*"
Last edited by twinnyfo; Apr 19 '18, 10:04 PM.Comment
-
A quick note: If you are referring to controls on the form you are currently using, instead ofForms![Inquiry Record]!Text259
, you can simply use "Me":Me.Text259
.
Also, when using a wildcard (also because you are using text fields, you must include single quotes around the search text. Thus:
Code:[ReceiptNumber] Like '*" & Me.Text259 & "*' " & _ "Or [ANumber] Like '*" & Me.Text259 & "*' " & _ "Or [SerialNumber] Like '*" & Me.Text259 & "*'"
Additionally, I will encourage you to name your controls something meaningful, rather than simply Text259. Instead designate it something like txtSearch, so that each time you see that control referenced in your code, you know the purpose of that control. This is all part of having a consistent naming convention for your projects. You can Google search DB Naming conventions--just pick one and stick with it.
Hope this hepps!Comment
-
-
Twinnyfo: Please see coding below. I am still receiving the popup box asking for values
Code:Option Compare Database Private Sub txt.Search_AfterUpdate() On Error GoTo EH Dim strFilter As String strFilter = "[ReceiptNumber] Like '*" & Me.Text259 & "*' " & _ "Or [ANumber] Like '*" & Me.Text259 & "*' " & _ "Or [SerialNumber] Like '*" & Me.Text259 & "*' " & _ Me.Filter = strFilter Me.FilterOn = True Exit Sub EH: MsgBox "There was an error filtering the Form!" vbCrlf & vbCrlf & _ Err.Number & vbCrlf & _ Err.Description & vbCrlf & vbCrlf & _ "Please contact your Database Administrator" vbCritical , "WARNING!" Exit Sub End Sub Private Sub Form_AfterUpdate() End Sub
Comment
-
Please read Before Posting (VBA or SQL) Code. This will make it a lot easier for everyone. You as well as those trying to help you. In this case I can't see how the code you've posted here could possibly run. If you follow the linked instructions we should get past those easily avoided issues though.
Originally posted by mcervenka1mcervenka1:
I am still receiving the popup box asking for values
You've probably used field names that are inaccurate, or simply not available in the dataset you're using. The clue should always be in the message that pops up.
In your case, but not always, your filter string could be set up using :
Code:With Me strFilter = "([ReceiptNumber] Like '*%RS*') OR " _ & "([ANumber] Like '*%RS*') OR " _ & "([SerialNumber] Like '*%RS*')" .Filter = Replace(strFilter, "%RS", .Text259) .FilterOn = True End With
Last edited by NeoPa; Apr 20 '18, 01:01 AM.Comment
-
NeoPa,
For a moment I thought you lost your mind, but line 5 brought it all together! I was thinking about a way to simplify the filter string I wrote, but thought the straightforward approach would be fine.
One question: doLike
statements require the usage of parentheses when paired withOr
statements?
Great insight and thanks!Comment
-
Originally posted by TwinnyFoTwinnyFo:
I was thinking about a way to simplify the filter string I wrote, but thought the straightforward approach would be fine.
Originally posted by TwinnyFoTwinnyFo:
One question: doLike
statements require the usage of parentheses when paired withOr
statements?
Consider [A] & [B] are Boolean fields.
Code:WHERE [NOPARSE][[/NOPARSE]A] = TRUE AND [NOPARSE][[/NOPARSE]B]
So, I always use parentheses to show that :
Code:WHERE ([NOPARSE][[/NOPARSE]A] = TRUE) AND ([NOPARSE][[/NOPARSE]B])
Code:WHERE ([NOPARSE][[/NOPARSE]A] = (TRUE AND [NOPARSE][[/NOPARSE]B]))
WHERE
clause.Last edited by NeoPa; Apr 20 '18, 05:07 PM.Comment
Comment