AllowZeroLength

By | 2002-06-01

All fields in the selected table are processed and the AllowZeroLength property of the fields are set to either True or False, depending on the Status given as the finaal parameter The function returns a boolean value that can be used by the user to determin other operations.

Original Author: Killcrazy

Inputs

strDatabase = Full database path
strTableName = Name of table to be processed
Status : True / False

Returns

True/False

Code

Function AllowZeroLength(strDatabase As String, strtablename As String, status As Boolean) As Boolean
Dim db As Database
Dim td As TableDef
Dim fd As Field
On Error GoTo Error_Handler
Set db = OpenDatabase(strDatabase)
Set td = db.TableDefs(strtablename)
  'loop through the fields in the selected recordset
  For Each fd In td.Fields
    'Check the field type, and only change the value of text and memo fields
    If fd.Type = dbText Or dbMemo Then
      If status = True Then
         fd.AllowZeroLength = True
      Else
        fd.AllowZeroLength = False
      End If
    End If
  Next fd
  
  AllowZeroLength = True
  ' Exit Early to avoid error handler.
  Exit Function
Error_Handler:
  ' Raise an error.
  Err.Raise Err.Number, "AllowZeroLength", "Could not process fields.", Err.Description
  AllowZeroLength = False
  
  ' Reset normal error checking.
  Resume Next
  
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.