Solved

Issue with VBA Function when adding criteria in Access Query

Posted on 2015-02-21
7
207 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
7 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
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
Comment Utility
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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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
Comment Utility
This solution worked except I had to divide by 100 I stead of 100000. Thus worked great. Thanks.
0

Featured Post

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

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel 2016 VBA - userform and z-Order of controls 11 33
Dateadd 3 20
TT Text To Column Based On Criteria 3 18
TT Add Column 10 11
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 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

11 Experts available now in Live!

Get 1:1 Help Now