Solved

Variance between values, access vba

Posted on 2013-01-04
6
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

756 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