473,651 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query ignoring functions returned value

Hi,
I'm not sure that I have the right group, so please bear with me.
Recently I created a fuction in the MS Access VBA IDE. The function returns
a Boolean.
I created the function to use as criteria in an Access query, and then I
discovered a problem.
The query runs ok, but it's apparently ignoring the functions return val.
It doesn't matter whether the function returns true, or false. If I
remember correctly (I haven't worked on it for a couple of days) the query
behaves as though the function always returns false, or was that true?
I've stepped through the function and observed that it is returning the
correct values, but the resulting recordset indicates otherwise
Has anyone experienced this, or know anything about this?
I'd be most gratefull for any help.
--
TIA
Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au
Mar 6 '06 #1
8 1926

"Vince Morgan" <vi****@UNSPAMo ptusnet.com.au> wrote in message
news:44******** **************@ news.optusnet.c om.au...
Hi,
I'm not sure that I have the right group, so please bear with me.
Recently I created a fuction in the MS Access VBA IDE. The function
returns
a Boolean.
I created the function to use as criteria in an Access query, and then I
discovered a problem.
The query runs ok, but it's apparently ignoring the functions return val.
It doesn't matter whether the function returns true, or false. If I
remember correctly (I haven't worked on it for a couple of days) the query
behaves as though the function always returns false, or was that true?
I've stepped through the function and observed that it is returning the
correct values, but the resulting recordset indicates otherwise
Has anyone experienced this, or know anything about this?
I'd be most gratefull for any help.
--
TIA
Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au

You haven't posted either the function or the query, so here is an example:
The function is designed to be used in a query so it is defined as public
and it accepts a variant argument since database fields can have null
values. The purpose of the function is simply to test whether a field (the
contact's name) is Bob. It returns a True/False value which is used in the
query below.

Public Function NameIsBob(varVa lue As Variant) As Boolean
If varValue = "Bob" Then
NameIsBob = True
End If
End Function
SELECT ConID, ConName,
NameIsBob([ConName]) AS ConIsBob
FROM tblContact
If you still haven't found what's going wrong, then post the function and
the SQL of the query.
Mar 6 '06 #2

"Vince Morgan" <vi****@UNSPAMo ptusnet.com.au> wrote in message
news:44******** **************@ news.optusnet.c om.au...
Hi,
I'm not sure that I have the right group, so please bear with me.
Recently I created a fuction in the MS Access VBA IDE. The function
returns
a Boolean.
I created the function to use as criteria in an Access query, and then I
discovered a problem.
The query runs ok, but it's apparently ignoring the functions return val.
It doesn't matter whether the function returns true, or false. If I
remember correctly (I haven't worked on it for a couple of days) the query
behaves as though the function always returns false, or was that true?
I've stepped through the function and observed that it is returning the
correct values, but the resulting recordset indicates otherwise
Has anyone experienced this, or know anything about this?
I'd be most gratefull for any help.
--
TIA
Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au


You haven't posted either the function or the query, so here is an example:
The function is designed to be used in a query so it is defined as public
and it accepts a variant argument since database fields can have null
values. The purpose of the function is simply to test whether a field (the
contact's name) is Bob. It returns a True/False value which is used in the
query below.

Public Function NameIsBob(varVa lue As Variant) As Boolean
If varValue = "Bob" Then
NameIsBob = True
End If
End Function
SELECT ConID, ConName,
NameIsBob([ConName]) AS ConIsBob
FROM tblContact
If you still haven't found what's going wrong, then post the function and
the SQL of the query.
Mar 6 '06 #3
"Anthony England" <ae******@oops. co.uk> wrote in message
news:du******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
Public Function NameIsBob(varVa lue As Variant) As Boolean
If varValue = "Bob" Then
NameIsBob = True
End If
End Function
SELECT ConID, ConName,
NameIsBob([ConName]) AS ConIsBob
FROM tblContact
If you still haven't found what's going wrong, then post the function and
the SQL of the query.


My funtion signature is identical to your example, except for one thing. I
didn't declare it Public AFAIK.
This is something I'm doing at work and I am not able to check the SQL
string until I return tomorrow afternoon.
I'll check it first thing.
Thank you Anthony for taking the time to reply, your help is much
appreciated.

--
Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au
Mar 7 '06 #4

"Vince Morgan" <vi****@UNSPAMo ptusnet.com.au> wrote in message
news:44******** **************@ news.optusnet.c om.au...
"Anthony England" <ae******@oops. co.uk> wrote in message
news:du******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
Public Function NameIsBob(varVa lue As Variant) As Boolean
If varValue = "Bob" Then
NameIsBob = True
End If
End Function
SELECT ConID, ConName,
NameIsBob([ConName]) AS ConIsBob
FROM tblContact
If you still haven't found what's going wrong, then post the function and
the SQL of the query.


My funtion signature is identical to your example, except for one thing.
I
didn't declare it Public AFAIK.
This is something I'm doing at work and I am not able to check the SQL
string until I return tomorrow afternoon.
I'll check it first thing.
Thank you Anthony for taking the time to reply, your help is much
appreciated.

--
Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au

Sorry, I should have mentioned that you don't have to put Public - if the
function is in a separate module then that will be the default. If it were
declared in a form's module or if you have explicitly declared it as
Private, then you would be getting a different sort of error. Then it would
say:
Undefined function 'YourFunctionNa me' in expression.

If I had to guess the problem, I would guess that either there is some fault
in the logic, so you have if...then but a condition is never met and the
function always returns either True or False. Or perhaps you do something
like this:

Function NameIsBob(varVa lue As Variant) As Boolean

Dim blnReturn As Boolean

If varValue = "Bob" Then
blnReturn = True
End If

End Function

where you intend to use the variable blnReturn to return the value, but omit
the final line of the function which should be:
NameIsBob = blnReturn
Without this final line, the function will always return False (the default
value for a boolean)

Anyway, this is all speculation until we see the function and query.
Mar 7 '06 #5
Anthony England wrote:
Anyway, this is all speculation until we see the function and query.


Some more speculation in case putting Public in does not help:

Does the function compare against a Null value?

James A. Fortune
CD********@Fort uneJames.com

Mar 7 '06 #6
"Anthony England" <ae******@oops. co.uk> wrote in message
news:du******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
You haven't posted either the function or the query, so here is an example: The function is designed to be used in a query so it is defined as public
and it accepts a variant argument since database fields can have null
values. The purpose of the function is simply to test whether a field (the contact's name) is Bob. It returns a True/False value which is used in the query below.


Well, it was just a moment of stupidity. I should have realized it was the
SQL string.
The function, which works fine, is below.
<>
Function IsAllUpper(str As Variant) As Boolean
Dim count As Long
Dim charCode As Long
If Not IsNull(str) Then
IsAllUpper = True
For count = 1 To Len(str)
charCode = Asc(Mid$(str, count, 1))
If Not ((charCode = 32) Or (charCode = 9)) Then
If charCode > 96 Then
IsAllUpper = False
Exit For
End If
End If
Next
End If
End Function
<>
However, the SQL string is frighteningly incorrect.

<>
SELECT [Test Module].POSITION
FROM [Test Module]
WHERE ((([Test Module].POSITION)=IsAl lUpper([POSITION])));

<>
I changed the last line to

"WHERE (IsAllUpper([POSITION]) = True)"

I dropped the function into the 'Criterea' box and imagined it understand
the implied condition. Too much C++ I guess.
Thank you Anthony, and James, very much for your help. And please excuse my
wasting your time
Much appreciated.
--
Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au
Mar 8 '06 #7

"Vince Morgan" <vi****@UNSPAMo ptusnet.com.au> wrote in message
news:44******** **************@ news.optusnet.c om.au...
"Anthony England" <ae******@oops. co.uk> wrote in message
news:du******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
You haven't posted either the function or the query, so here is an

example:
The function is designed to be used in a query so it is defined as public
and it accepts a variant argument since database fields can have null
values. The purpose of the function is simply to test whether a field

(the
contact's name) is Bob. It returns a True/False value which is used in

the
query below.


Well, it was just a moment of stupidity. I should have realized it was
the
SQL string.
The function, which works fine, is below.
<>
Function IsAllUpper(str As Variant) As Boolean
Dim count As Long
Dim charCode As Long
If Not IsNull(str) Then
IsAllUpper = True
For count = 1 To Len(str)
charCode = Asc(Mid$(str, count, 1))
If Not ((charCode = 32) Or (charCode = 9)) Then
If charCode > 96 Then
IsAllUpper = False
Exit For
End If
End If
Next
End If
End Function
<>
However, the SQL string is frighteningly incorrect.

<>
SELECT [Test Module].POSITION
FROM [Test Module]
WHERE ((([Test Module].POSITION)=IsAl lUpper([POSITION])));

<>
I changed the last line to

"WHERE (IsAllUpper([POSITION]) = True)"

I dropped the function into the 'Criterea' box and imagined it understand
the implied condition. Too much C++ I guess.
Thank you Anthony, and James, very much for your help. And please excuse
my
wasting your time
Much appreciated.
--
Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au



No problem. I don't know whether you will be pleased or not to learn that
the normal way to test whether a string is in all upper case is by using the
built-in StrComp function

?StrComp("Egg", "EGG",vbBinaryC ompare) returns 1

?StrComp("EGG", "EGG",vbBinaryC ompare) returns zero
Since the constant vbBinaryCompare =0, I would use the following to check if
a field was all upper case or not:

SELECT ID, MyField,
StrComp([MyField],UCase([MyField]),0)=0 AS IsUpperCase
FROM MyTable


Mar 8 '06 #8
"Anthony England" <ae******@oops. co.uk> wrote in message
news:du******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...


No problem. I don't know whether you will be pleased or not to learn that
the normal way to test whether a string is in all upper case is by using the built-in StrComp function

?StrComp("Egg", "EGG",vbBinaryC ompare) returns 1

?StrComp("EGG", "EGG",vbBinaryC ompare) returns zero
Since the constant vbBinaryCompare =0, I would use the following to check if a field was all upper case or not:

SELECT ID, MyField,
StrComp([MyField],UCase([MyField]),0)=0 AS IsUpperCase
FROM MyTable


That's a lot more elegant and a whole lot faster I'm sure. Time was not my
friend when I wrote the query and I haven't used Access since about 2001.
Excuses aside, I'll be using the above method from hereon :)
Thank you again Anthony,
Very much appreciated,
Regards,

Vince Morgan
Remove UNSPAM
vi****@UNSPAMop tusnet.com.au
Mar 8 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2927
by: lawrence | last post by:
A very strange bug. www.monkeyclaus.org is run by a cms I'm developing. One of types of users we allow is "justTestingTheSite", a type of user I developed to give demo's to prospective clients. The purpose of this level of security is to let someone log in and see everything as if they were root, and yet not be able to update or delete anything, as they have no real priveledges at all. I just logged in as root and created such an...
9
2457
by: Börni | last post by:
Hi, I have an sql query like this: SELECT column FROM table WHERE column1="3" AND column2="1" This query works perfectly if i run it in the command line, to be exactly it return two results. But if i run it from php i just get the first of the two results. Any ideas? Mysql 4.1.8 php 5.0.3
20
10132
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
3
1943
by: Nick Truscott | last post by:
<? // scoreinput.php - input a match score when match selected from list ?> <html> <head> <basefont face="Verdana"> </head> <body>
22
3039
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20 3, NULL, 9, 82, 25
4
2843
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table that links to a transaction items table that links to the products table: (User Table) UserID Other user data
6
29931
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access newsgroups, the access support centre, I can seem to find no similar situation. I am not using any references, or VBA at all in the first place. I am trying to set up a simple (or so I thought) query to work with the text of two tables. ...
7
7344
by: rguarnieri | last post by:
Hi! I'm trying to create a query with a boolean expression like this: select (4 and 1) as Value from Table1 this query return always -1, but when I make the same calculation in visual basic, the value returned is 0. Can anyone tell me why the expression (4 and 1) return different value
3
2309
by: bob laughland | last post by:
Hi All, I have a SQL query like this (I have tried to break the problem down to simplify it), select rowid from table where name in ('a', 'b', 'd') group by rowid Here is an example of data in the table rowid name
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.