filter subform based of textbox control value vba access

this line not working for me : (how to fix it?)
Me.frmName_sub.Form.Filter = "[fieldName] <> 0 And """ & Me.frmName_sub.Form.txtBox.Value & """ <> Null"
drtopservAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What's "[FieldName]"? Is that a placeholder, or do you actually have a field in the subform named "FieldName"?

You can try using the Nz function instead (and get rid of the quotes):

Me.frmName_sub.Form.Filter = "[fieldName] <> 0 And " & Nz(" & Me.frmName_sub.Form.txtBox & ",0) <>0"

Also, make sure that "frmName_Sub" is the name of the Subform CONTROL on your form. This may or may not be the same as the name of the Form you're using as a Subform.

You also have to turn the filter ON:

Me.frmName_Sub.Form.FilterOn = True
0
drtopservAuthor Commented:
compile error:
Expected : end of statement
0
drtopservAuthor Commented:
[FieldName] is a actual field in the subform
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

drtopservAuthor Commented:
Me.frmName_sub.Form.txtBox.Value  means:
me=main form
frmName_sub=subform (in the main form )
txtbox=name of the textbox in the subform
0
Gustav BrockCIOCommented:
Not quite sure what you are trying to accomplish, but try with:

Me!frmName_sub.Form.Filter = "[fieldName] <> 0 And [txtBox] Is Not Null"

/gustav
0
drtopservAuthor Commented:
Well I`ll explain more clearly.
I have a main form with a continues sub_form .
i have put a text box control inside the sub_form that and it`s source controls is (dsum function)
I need to click on a control in a main form and perform a filter in this sub_form based of the textbox control inside the sub_form (mentioned upbove) , I wrote this line that didn`t work:
Me.frmName_sub.Form.Filter = "[fieldName] <> 0 And """ & Me.frmName_sub.Form.txtBox.Value & """ <> Null"
0
drtopservAuthor Commented:
To refer to a control in subform when i`m in main form is:
Me!Subform1.Form!ControlName

this didn`t work :
Me.subform1.Form.Filter = "Nz(" & Me!Subform1.Form!ControlName & ",0) <>0"
Me.subform1.Form.Filteron=true
0
Gustav BrockCIOCommented:
If you wish to filter the subform for records where this DSum calculation is Not Null you must filter on the textbox as seen from the subform - as in my filter expression.

/gustav
0
drtopservAuthor Commented:
Me!frmName_sub.Form.Filter = "[fieldName] <> 0 And [txtBox] Is Not Null"

 your [txtBox] means field name in subform.
i`m talking about textbox control into subform..
your line didn`t work.
I`ll be very glad if you have a sample to look at .
0
Gustav BrockCIOCommented:
If it not a field, your filter makes no sense. Say the textbox contains the sum 9:

Me!frmName_sub.Form.Filter = "[fieldName] <> 0 And 9 Is Not Null"

would return anything where [fieldName] <> 0.
If the sum is Null:

Me!frmName_sub.Form.Filter = "[fieldName] <> 0 And Null Is Not Null"

would return nothing.

/gustav
0
drtopservAuthor Commented:
OK , I understand now.
then how you may help to tell :
don`t show me a records where this textbox control value is null or 0 ?
0
drtopservAuthor Commented:
I could solve the problem if i use the dsum cals as a calc field in a query .
is there any other solution?
0
Gustav BrockCIOCommented:
> .. use the dsum cals as a calc field in a query .

That should work. Then the field will be a part of the recordsource for the subform and can be filtered on like any other field.

/gustav
0
drtopservAuthor Commented:
yes that what i said, is there any chance to run it in another way?
means to refer/talk with textbox value in a subform ?
0
Gustav BrockCIOCommented:
Not really. You could run a query similar to the one you use for the subform including the DSum expression filtering on the this for the value from the subform to find the matching IDs of the subform.
Then adjust the recordsource to use:

  .. where ID IN (a, b, c, .., n)

where a, b, c, etc. are the IDs found.

That will filter the subform.
To remove the filter, apply the origianl recordsource.

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drtopservAuthor Commented:
Well I think i`ll go after this solution. thanks alot gustav.
is it possible to ask another Q but related to this form ?
0
Gustav BrockCIOCommented:
No problem.

/gustav
0
drtopservAuthor Commented:
thnx, Well I have at this main form (Name MainA) a subform(Named SubB)  that have a command button that opens another form(Named SubformC) ,when click on it . and in that another form(subformC) i have 3 subform(named SubformD/E/F) each subform is a query source control have based (filtered) on field value in the previous subform .

this apps working in multi user environment.
is there a chance to locks these records(3 subform) (SubformD/E/F) for accessing when 1 user are in them?
0
Gustav BrockCIOCommented:
No one that is bulletproof.

But you could use the OnEnter and OnExit events of the subforms to set and reset a field in a table to indicate a lock. This you could check at the OnActivate of the form holding the subforms; if set, you can adjust AllowEditing to False for the subforms. If reset, allow editing.
If you use Now for value of the flag, you can check if this is more than a day old - if so, the flag has probably not been reset, and editing should be allowed anyway.

/gustav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.