Solved

Variance between values, access vba

Posted on 2013-01-04
6
381 Views
Last Modified: 2013-01-05
I have a form with a combo that allows me to select nom cc with a view to filtering on that [nom cc], I have a label controlled by two buttons that allow me to set the variance either 0 for exact ie if i select 1.3 then i just want [nom cc] of 1.3 but if i select .1 then I want records with [nom cc] of 1.2, 1.3 and 1.4 ie .1 over and below the selected. If the record has no [nom cc] value then that shown.

Not quite sure how to set the filter for that I have some code I think its a math problem:

Private Sub CBNom_AfterUpdate()
Dim StrFilter, StrCBIn As String
StrCBIn = Me.CBNom.Value
StrFilter = "((abs([Nom CC] - " & Me.LblVNomCount.Caption & ")" & ")<=" & Me.LblVNomCount.Caption & ") Or (isnull([nom cc]))"


Debug.Print StrFilter
Me.Form.Filter = StrFilter

Me.Form.FilterOn = True
Me.Form.Requery
End Sub

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38746315
Try this:
Private Sub CBNom_AfterUpdate()
    Dim strFilter, dblCBIn As Double
    dblCBIn = Me.CBNom.Value
    strFilter = "(Abs([Nom CC] - " & dblCBIn & ") <= " & Me.LblVNomCount.Caption & ") Or (IsNull([nom cac]))"
    Me.Filter = sttFilter
    Me.FilterOn = True
End Sub

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 38746326
the maths is still incorrect
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38746330
What results are you getting?
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 29

Expert Comment

by:IrogSinta
ID: 38746335
Is your data type for [nom cc] set to Number in the table?
0
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 38746376
Check this version:
Private Sub CBNom_AfterUpdate()
Dim StrFilter As String, StrCBIn As Double, StrVr as Double
StrCBIn = CDBL(Me.CBNom.Value)
StrVr = CDBL(nz(Me.LblVNomCount.Caption,0))                  ' Check here assigned value

StrFilter = "([Nom CC] >= " & StrCBIn - StrVr & " AND [Nom CC] <= " & StrCBIn + StrVr & ") Or isnull([nom cc])"


Debug.Print StrFilter
Me.Form.Filter = StrFilter

Me.Form.FilterOn = True
Me.Form.Requery
End Sub

Open in new window

May be better to upload sample DB with this form?
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 38746409
thank you and happy new year
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

792 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