InFlight
User
- Local time
- Tomorrow, 07:59
- Joined
- Jun 11, 2015
- Messages
- 130
Hi
I found this code and using it. My problem is i am addind a field called PhoneNum.
it adds it ok but i want to change the InPut Mask to
varMask = "!\(999" & Chr(34) & ")" & Chr(34) & "900\ 0000;;_"
I found this code and using it. My problem is i am addind a field called PhoneNum.
it adds it ok but i want to change the InPut Mask to
varMask = "!\(999" & Chr(34) & ")" & Chr(34) & "900\ 0000;;_"
Code:
Public Sub fSetOrdinal(db As Database, strTbl As String, intOrdinal As Integer, strNewFieldName As String)
' ---------------------------------------------------------
' Name: fSetOrdinal
' Purpose: To add a new field into a table at a specific Ordinal Number
' Inputs: db - the database to use
' strTbl - name of the table to add field to
' intOrdinal - ordinal position for new field
' strNewFieldName - name for new field to be added
' Returns: Nothing
' ----------------------------------------------------------
Dim tbl As TableDef
Dim fld As Field
Dim fldLoop As Field
Dim intLoop As Integer
Set tbl = db.TableDefs(strTbl)
' check for existence of same column name
For Each fldLoop In tbl.Fields
If fldLoop.Name = strNewFieldName Then
MsgBox ("This column (field) name [" & strNewFieldName & "] already exists in table: " & strTbl)
Exit Sub
End If
Next
'ensure all fields have a unique ordinal value - ie: reset ALL ordinals
tbl.Fields.Refresh
For intLoop = 0 To tbl.Fields.Count - 1
tbl.Fields(intLoop).OrdinalPosition = intLoop
Next
tbl.Fields.Refresh
'***Add NEW Column***
' loop thru all fields and ensure no field has the same ordinal that you want to add
For Each fldLoop In tbl.Fields
' if existing field has same ordinal then increase all subsequent field ordinals by 1
If fldLoop.OrdinalPosition = intOrdinal Then
For intLoop = tbl.Fields.Count - 1 To intOrdinal Step -1
tbl.Fields(intLoop).OrdinalPosition = intLoop + 1
Next
End If
Next
tbl.Fields.Refresh
' to make function more robust you could pass these field parameters also
' i did not just for demo purposes
Set fld = tbl.CreateField(strNewFieldName, dbText, 10)
fld.Properties("Required").Value = False
fld.Properties("AllowZeroLength").Value = True
fld.OrdinalPosition = intOrdinal
tbl.Fields.Append fld
tbl.Fields.Refresh
End Sub