Solved

locating null fields in an access database

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

19 Experts available now in Live!

Get 1:1 Help Now