Solved

locating null fields in an access database

Posted on 2000-04-24
4
150 Views
Last Modified: 2010-05-02
Is there a way (through vb code) to change all null fields in a very large table to empty strings  without reading each field.

 
0
Comment
Question by:Diehl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Crin
ID: 2744515
First you should be certitude that empty strings are allowed.

Then use
Database.Execute "Update Table set Field = '' where IsNull(Field);"

This should work.

Sincerely yours,

Crin
0
 
LVL 6

Expert Comment

by:Marine
ID: 2744569
This should work .

UPDATE <tableName> SET <tableField> = "" WHERE <fieldname>=Null
0
 
LVL 32

Accepted Solution

by:
bhess1 earned 50 total points
ID: 2744651
If it is more than one field that can be null, you'll have to execute the above queries more than once.

The best method depends on what access method you are using.  I'm going to use a DAO example, but ADO can be done just about the same way.

This procedure requires you to pass the opened Database that the table is in, and a table name.

Sub ClearNulls(db As Database, tName as String)
Dim S as String, I as Integer, J as Integer

For I = 0 to db.TableDefs.Count - 1
  ' find the tabledef
  If UCase(db.TableDefs(I).Name) = UCase(tName) Then
    ' once found, get the fields from the tabledef
    With db.Tabledefs(I)
      For J = 0 to .Fields.Count - 1
        ' only update text or memo fields
        If .Fields(J).Type = dbText or .Fields(J).Type = dbMemo Then
          ' execute an SQL statement to set nulls to empty strings (assumes this is allowed)
          db.Execute "UPDATE " & tName & " SET " & .Fields(J).Name & " = '' Where IsNull(" & .Fields(J).Name & ");"
        End If
      Next J
    End With
  End If
Next I    
0
 
LVL 6

Expert Comment

by:Marine
ID: 2745112
I don't think so bhess1 i can execute it only once and update all fields whcih will contain null values. I don't even have to specify where condition and all colums will be updated to "" if they contain null
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 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