Solved

locating null fields in an access database

Posted on 2000-04-24
4
151 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

728 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