?
Solved

locating null fields in an access database

Posted on 2000-04-24
4
Medium Priority
?
152 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:
Brendt Hess earned 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

764 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