[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

filter subform based of textbox control value vba access

Posted on 2014-08-21
19
Medium Priority
?
1,964 Views
Last Modified: 2014-08-30
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"
0
Comment
Question by:drtopserv
  • 11
  • 7
19 Comments
 
LVL 85
ID: 40275884
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
 

Author Comment

by:drtopserv
ID: 40275899
compile error:
Expected : end of statement
0
 

Author Comment

by:drtopserv
ID: 40275901
[FieldName] is a actual field in the subform
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:drtopserv
ID: 40275910
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
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40275928
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
 

Author Comment

by:drtopserv
ID: 40276814
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
 

Author Comment

by:drtopserv
ID: 40277311
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
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40277459
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
 

Author Comment

by:drtopserv
ID: 40277499
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
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40277530
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
 

Author Comment

by:drtopserv
ID: 40277542
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
 

Author Comment

by:drtopserv
ID: 40277588
I could solve the problem if i use the dsum cals as a calc field in a query .
is there any other solution?
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40278267
> .. 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
 

Author Comment

by:drtopserv
ID: 40278301
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
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 1500 total points
ID: 40278311
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
 

Author Comment

by:drtopserv
ID: 40278319
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
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40278323
No problem.

/gustav
0
 

Author Comment

by:drtopserv
ID: 40278330
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
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 40278344
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question