Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MSAccess/VBA/DAO query result set not as expected

Posted on 2007-11-20
3
Medium Priority
?
1,942 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

782 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