Solved

Variance between values, access vba

Posted on 2013-01-04
6
376 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 29

Expert Comment

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now