473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using filter error because of DSUM function

222 100+
dears

I have a continuous forms. It contains 2 fields [customername][customerid]
I made another field to check their accounts. it is [account].

the source of [account] is based on a DSUM function. "it is working well"

Now I want to filter this form on a criteria where account > 0.

It is not working using this code
Expand|Select|Wrap|Line Numbers
  1. Filter = "Balance > " & 0
  2. Me.FilterOn = True
  3.  

I was searching this topics i found that it is impossible to do it, because the [account] field is based on a DSUM function. Is that true ?

Do you think is there any better method for checking my customers account ?




Thank you in advance

Regards,


WASSIM S DACCACHE
Oct 13 '08 #1
4 2192
Stewart Ross
2,545 Expert Mod 2GB
Hi Wassim. DSUM is not the problem at all. Line 1 in your filter code is incorrect; it should be referring to the form's filter property, but by leaving out the shortcut form reference (the Me keyword) you are actually referring to an undeclared variable called Filter - and when you then set the form filter on there is no filter to apply!

It ought to be

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "Balance > 0"
  2. Me.FilterOn = True
  3.  
By the way, there is no need to separate out the 0 when putting together the filter string.

You can, and should, set the VBA compiler options to require variable declarations - it will help trap this type of 'undeclared variable by mistake' problem. From the VB Editor choose Tools, Options, and ensure Require Variable Declaration is checked. See also the use of compiler directive Option Explicit in the header of a module, as this also forces explicit declaration of all variables within that module.

At least then if you did not intend to use a variable (as in this instance when you were trying to set a form's filter property) the compiler error will flag that you have done something wrong...

-Stewart
Oct 13 '08 #2
wassimdaccache
222 100+
Hi Wassim. DSUM is not the problem at all. Line 1 in your filter code is incorrect; it should be referring to the form's filter property, but by leaving out the shortcut form reference (the Me keyword) you are actually referring to an undeclared variable called Filter - and when you then set the form filter on there is no filter to apply!

It ought to be

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "Balance > 0"
  2. Me.FilterOn = True
  3.  
By the way, there is no need to separate out the 0 when putting together the filter string.

You can, and should, set the VBA compiler options to require variable declarations - it will help trap this type of 'undeclared variable by mistake' problem. From the VB Editor choose Tools, Options, and ensure Require Variable Declaration is checked. See also the use of compiler directive Option Explicit in the header of a module, as this also forces explicit declaration of all variables within that module.

At least then if you did not intend to use a variable (as in this instance when you were trying to set a form's filter property) the compiler error will flag that you have done something wrong...

-Stewart
Dear sir

I Appreciate your kind reply.

I did it, I got a new input box with a "balance" title.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.     Me.Filter = "balance > 0"
  4.     Me.FilterOn = True
  5.  
any idea?
I checked that my field [account] name is "balance"
Oct 13 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Wassim, it is the fields of the underlying query or table that you are filtering, not controls on your form. If you want to filter on a field called Balance you must have a field called Balance in your form's recordsource query or table for this to work.

If you are trying to filter on the value of a control shown on your form, a control that is not named the same as a bound field, the simple answer is that you cannot.

If possible place calculated fields in the recordsource query of your form. You will then be able to refer to the calculated field just as with any other field

-Stewart
Oct 13 '08 #4
wassimdaccache
222 100+
Wassim, it is the fields of the underlying query or table that you are filtering, not controls on your form. If you want to filter on a field called Balance you must have a field called Balance in your form's recordsource query or table for this to work.

If you are trying to filter on the value of a control shown on your form, a control that is not named the same as a bound field, the simple answer is that you cannot.

If possible place calculated fields in the recordsource query of your form. You will then be able to refer to the calculated field just as with any other field

-Stewart
aaa OK OK now I understood. I am not able to filter [balance] because it is not on the recordsource of my form.

Actually I did as you advice me. I put the source of balance textbox in the recordsource of my form , I use this code filter above and it is working well.


THANK YOU AGAIN

Have a nice day :)
Oct 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
7
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals....
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
1
by: danielgoss | last post by:
Hi I have a report that has loads of textboxes that calculate things based on the value on another textbox in the report. I have put a hidden textbox on my report that gets its value from an...
2
by: kidfortoday | last post by:
Ahhh... I can't figure this out, can someone help? I'm using Access 2003. I have 2 tables here: One is for each person, called tblPartners. One is for each distribution by a partner,...
3
patjones
by: patjones | last post by:
Good morning all: In what seems like an ongoing saga to make the DSum function do what I need it to, I am now having trouble with a user-defined function in my VBA module. Here's the offending...
7
jmoudy77
by: jmoudy77 | last post by:
I've got some vb code that gives me a "previous operation cancelled" error when I try and open the form as a subform in a tabbed control. When I open the form itself I don't get the error. Does...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.