Solved Filter form Only (1 Viewer)

theinviter

Registered User.
Local time
Yesterday, 16:56
Joined
Aug 14, 2014
Messages
240
Dears:
i have created a form that contain a search textbox, once user update then it will filter the form.
i have applied the below code but it apply the filter on both form and subform .
so can you please advise me how to correct to filter form only.
Private Sub FindCode_AfterUpdate()

On Error GoTo errhandler

''n = 1 / 0 ' cause an error



Dim strFilter As String

strFilter = ""

If Len(Me.FindCode & "") <> 0 Then

strFilter = " or '' &
Code:
 Like '" & Me.FindCode & "'"

End If



If Len(Me.FindCode & "") <> 0 Then

strFilter = strFilter & " or '' & [Other Code] Like '" & Me.FindCode & "'"

End If





If Len(strFilter) > 0 Then

strFilter = Mid(strFilter, 4)

With Me

.Filter = strFilter

.FilterOn = True
Me.Table1_Subform.SetFocus
DoCmd.GoToControl ("[Qnty_IN]")
DoCmd.GoToRecord , , acNewRec
End With

Else

'Me.Filter = ""

Me.FilterOn = False

End If



Exit Sub

errhandler:

' error handling code

Resume Next
End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:56
Joined
Feb 28, 2001
Messages
27,167
If the sub-form is linked to the main form via the Parent/Child links that reflect a relationship between parent and child, then the sub-form WILL be affected by the filter when the main form requeries and that requery is propagated down to the sub-form. Access does that requery because ignoring a declared parent/child relationship would violate referential integrity.

The question is, why would you NOT want the sub-form to react to changes in its parent that change what is visible? Stated another way, if you truly have a relationship between parent form and child form, why would you wish to ignore the relationship?

If this is not what you meant by "i have applied the below code but it apply the filter on both form and subform so can you please advise me how to correct to filter form only" then please explain in a bit more detail.

ADDENDUM: If the sub-form DOES NOT have anything in the Parent/Child links AND does not have a declared relationship - but you still see that change, then we would have to see the SQL version of the .Recordsource used for each of the two forms to figure out why.
 

theinviter

Registered User.
Local time
Yesterday, 16:56
Joined
Aug 14, 2014
Messages
240
If the sub-form is linked to the main form via the Parent/Child links that reflect a relationship between parent and child, then the sub-form WILL be affected by the filter when the main form requeries and that requery is propagated down to the sub-form. Access does that requery because ignoring a declared parent/child relationship would violate referential integrity.

The question is, why would you NOT want the sub-form to react to changes in its parent that change what is visible? Stated another way, if you truly have a relationship between parent form and child form, why would you wish to ignore the relationship?

If this is not what you meant by "i have applied the below code but it apply the filter on both form and subform so can you please advise me how to correct to filter form only" then please explain in a bit more detail.

ADDENDUM: If the sub-form DOES NOT have anything in the Parent/Child links AND does not have a declared relationship - but you still see that change, then we would have to see the SQL version of the .Recordsource used for each of the two forms to figure out why.
Thanks for explanation.
Yes the form is linked to subform. As there is 2 criteria to filter the for by ited code and other code.
When the user enter the code in text field then, will filter the form to that record. As the subform has other data related to item code.
What I want is that when user enter the code in text field then. It will for that code in ( code, and other code) 2 field. And then filter the form. If not found then show a msgbox ( Record not found).
I will share the database later.
 

theinviter

Registered User.
Local time
Yesterday, 16:56
Joined
Aug 14, 2014
Messages
240
Find the database in link below

 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:56
Joined
Feb 28, 2001
Messages
27,167
OK, it is clear that we have a minor language issue here. So let me repeat what I got out of that.

You have 2 fields that will be used to filter some table. You want to put the filter strings in one or two text boxes and have the form test for whether there is a record matching the pair of field values. If you find a match, display the record. If you don't find a match, display a message.

Did I understand that correctly?

If I got that right, this whole situation depends on building the "criteria" string, which is a WHERE clause except you don't include the word "WHERE" in the clause. I opened the DB in the linked post but I didn't see enough to help me understand where that was going. So I'll try to describe this in English and hope you can follow it.

The criteria string might resemble

strCriteria = "( [Date_] >= #" & Me.StartDate & "# ) AND ( [Date_] <= #" & Me.EndDate & "# )"

You build that string as step 1. Step 2 would be to use

lRecordCount = DCount( "*", "Stock", strCriteria )

Then you would test whether lRecordCount is 0.

Code:
IF lRecordCount = 0 Then
    MsgBox "No records found", vbOKOnly, "No Records"
Else
    Me.Filter = strCriteria
    Me.FilterOn = TRUE
    Me.ReQuery
End if

There would obviously be more to it than this, but this is showing the basics. The problem is, your description from the start of the problem to the most recent description does not seem consistent. Which makes me wonder if there is more going on than you have described. We all want to help folks here, but the difficulty will always be whether our language differences become a barrier to understanding. Inconsistent descriptions can be a problem that makes help harder to offer. Don't give up, but we need to have as much clarity as possible in understanding what you REALLY want to do.
 

theinviter

Registered User.
Local time
Yesterday, 16:56
Joined
Aug 14, 2014
Messages
240
Please find the correct file attached, as i Update the filed "Code" so need the form to filer for item code and other code. as i need the filter to be applied in the form only.
 

Attachments

  • Stock Card - Copy.accdb
    1.7 MB · Views: 107

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:56
Joined
May 7, 2009
Messages
19,230
test and check.
 

Attachments

  • Stock Card - Copy (3).accdb
    820 KB · Views: 125

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:56
Joined
May 7, 2009
Messages
19,230
here on AfterUpdate of combo/textbox
 

Attachments

  • Stock Card - Copy (3).accdb
    832 KB · Views: 124

Users who are viewing this thread

Top Bottom