Solved

Variance between values, access vba

Posted on 2013-01-04
6
371 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

708 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

19 Experts available now in Live!

Get 1:1 Help Now