PC User
Registered User.
- Local time
- Yesterday, 18:47
- Joined
- Jul 28, 2002
- Messages
- 193
I found this very useful function on the internet and I'm trying to get it to work. I keep getting an error, but it appears that the code is correct. Can anyone else get to cycle through a table and change the properties of all text and memo fields?
Thanks,
PC
Code:
'**************************************
' Name: AllowZeroLength
' Description: All fields in the selected table are processed and the AllowZeroLength property of the fields are set to ei
' 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.
'
' By: Killcrazy
'
' Inputs:strDatabase = Full database path
'
'strTableName = Name of table to be processed
'Status : True / False
'
' Returns:True/False
'
'Assumes:None
'
'Side Effects:none
'
'Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.2279/lngWId.1/qx/vb/scripts/ShowCode.htm
'for details.
'**************************************
Function AllowZeroLength(strtablename As String, Status As Boolean) As Boolean
'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 = CurrentDb
'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 t
' he 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
PC
Last edited: