Solved

MSAccess/VBA/DAO query result set not as expected

Posted on 2007-11-20
3
1,931 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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.

914 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

16 Experts available now in Live!

Get 1:1 Help Now