Solved

Issue with VBA Function when adding criteria in Access Query

Posted on 2015-02-21
7
212 Views
Last Modified: 2016-02-10
Hi All,

I have a very simple function that I wrote to compare two number fields.  One field has 5 digits and another field has 7 digits.  I only care about the first 5 digits in the second field so I have a small function that trims the number and then does a compare and produces a result of 1 if it matches the conditions of the if statement, otherwise it produces a 0.  When I enter the function into an access query it runs without issue.  As soon as I put criteria that I want the function to only equal 1, below the function, the query freezes upon running and I cannot get out of it.  Below is the function.  If someone could help me I'd really appreciate it...

Option Compare Database

Public Function fnOVERBILL(BILLDATE As Double, MBHTDT As Double) As Double

Dim TERM As Double

TERM = CLng(Left(MBHTDT, 5))

If (BILLDATE > TERM) And (MBHTDT > 0) Then
    fnOVERBILL = 1
Else
    fnOVERBILL = 0

End If

End Function

Open in new window

0
Comment
Question by:Anthony6890
[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
7 Comments
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40623458
Try using this expression in the query:

    Test: Nz(BILLDATE, 0) > Val(Left(Nz([MBHTDT], 0), 5)) And Nz([MBHTDT], 0) > 0

and set the criteria for this column to: True

/gustav
0
 
LVL 1

Author Comment

by:Anthony6890
ID: 40623504
Thanks for getting back to me.  I just tried that and it still locks up on me.  Access enters a Not Responding phase.

-Anthony
0
 
LVL 1

Author Comment

by:Anthony6890
ID: 40623510
Gustav,

When I use your formula, and I don't put true in the criteria it runs without issue.  I know that there are currently no results for this query which is why I want to test it out.  It can produce a 0 for everyone; however, if I put "True" in the criteria I shouldn't have any results happen.

-Anthony
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 50

Expert Comment

by:Gustav Brock
ID: 40623518
Will this - without criteria - return any results:

    Test1: Val(Left(Nz([MBHTDT], 0), 5))
    Test2 Nz([BILLDATE], 0)

If so, try with these and the criteria as written:

    Test1: Val(Left(Nz([MBHTDT], 0), 5))
    Criteria: <[BILLDATE]

    Test2 Nz([BILLDATE], 0)
    Criteria: >0

/gustav
0
 
LVL 9

Accepted Solution

by:
Ramanhp earned 500 total points
ID: 40623553
I recommend try dividing the number of length 7 with 100000, and take the int part only and then do the matching criteria as per your logic..
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 40624218
1.  Are these actually date values, or is the data type of the field actually number?

2.  If number, what do the extra two characters in the MBHTDT column mean?

3.  Do you have any records where either the BILLDATE or the MBHTDT is NULL?
0
 
LVL 1

Author Closing Comment

by:Anthony6890
ID: 40624254
This solution worked except I had to divide by 100 I stead of 100000. Thus worked great. Thanks.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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