Solved

MSAccess/VBA/DAO query result set not as expected

Posted on 2007-11-20
3
1,930 Views
Last Modified: 2013-11-27
I have an application that I have to support that was written in MS-Access 2003 VBA with DAO access to ODBC PostgreSQL database tables.

The database was designed without the use of "no nulls" capability of PostgreSQL so a varchar field without valid data could be null, blank or space.

The db.OpenRecordset query is supposed to select all records where a particular varchar field (RecordType) is null, space or blank, but it is not selecting the null fields into the result set.  Can anyone see what might be wrong with the code snippet or suggest an alternative to ensure that nulls are included in the result set?

Please don't suggest changing it to ADO.  This system is in maintenance mode - I have better things to do with my time than rewriting old code.  I just need the result set to be as expected.
Set db = CurrentDb

Set rs = db.OpenRecordset("select * from <tablename> where [supplier] = 'name' and ([RecordType] = null or [RecordType] = '' or [RecordType] = ' ') order by [Sys_ID]")

Open in new window

0
Comment
Question by:ShineOn
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
GeraldHlasgow earned 500 total points
ID: 20321164
I'm not familiar with PostgreSQL so this is just a guess, but on most SQL databases that I've used if you want to check for a field being null you say

WHERE [FieldName] IS NULL

and not

WHERE [FieldName] = Null

Just a thought...
0
 
LVL 35

Author Comment

by:ShineOn
ID: 20321431
Thanks.  I didn't catch that.  

IS NULL is proper for PostgreSQL - it uses standard SQL.  

Sometimes it takes a second set of eyes... ;)
0
 
LVL 1

Expert Comment

by:GeraldHlasgow
ID: 20321477
Happy to lend an eye or two :-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

21 Experts available now in Live!

Get 1:1 Help Now