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