Create Field with Input Mask in DAO 
Author Message
 Create Field with Input Mask in DAO

Trying to create a field with an input mast in dao.  Here is my code:

    strMask = ">aaaaaaaa"

    Set tdf = db.TableDefs("Contacts")
        With tdf
            Set fld = .CreateField("altCode", dbText, 8)
                On Error Resume Next
                    fld.Properties("InputMask") = strMask
                    If Err.Number <> 0 Then
                        Set prp = fld.CreateProperty("InputMask",
dbText, strMask)
                        fld.AllowZeroLength = True
                        fld.Properties.Append prp
                    End If

                .Fields.Append fld

                Set idx = .CreateIndex("idxaltCode")
                    With idx
                        .Fields.Append .CreateField("altCode")
                    End With
                .Indexes.Append idx
                .Fields.Refresh
                .Indexes.Refresh
        End With

It does everything I want it to do except set the input mask.  Help
anyone?

Richard



Mon, 27 Oct 2003 21:55:17 GMT  
 Create Field with Input Mask in DAO
I think you need to append the fld to the Fields collection first.  The
following code worked on my Test database (A97).

***Code starts***
Public Sub AddField()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prp As DAO.Property
Dim idx As DAO.Index
Dim strMask As String

strMask = ">aaaaaaaa"

Set db = CurrentDb()
Set tdf = db.TableDefs("tblTest1")

With tdf
    Set fld = .CreateField("altCode", dbText, 8)
    .Fields.Append fld

On Error Resume Next
    fld.AllowZeroLength = True
    fld.Properties("InputMask") = strMask

    If Err.Number <> 0 Then
        Set prp = fld.CreateProperty("InputMask", dbText, strMask)
        fld.Properties.Append prp
    End If

    Set idx = .CreateIndex("idxaltCode")
    With idx
        .Fields.Append .CreateField("altCode")
    End With
    .Indexes.Append idx

    .Fields.Refresh
    .Indexes.Refresh
End With

Set idx = Nothing
Set prp = Nothing
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing

End Sub
***Code ends***

HTH
Van T. Dinh


Quote:
> Trying to create a field with an input mast in dao.  Here is my code:

>     strMask = ">aaaaaaaa"

>     Set tdf = db.TableDefs("Contacts")
>         With tdf
>             Set fld = .CreateField("altCode", dbText, 8)
>                 On Error Resume Next
>                     fld.Properties("InputMask") = strMask
>                     If Err.Number <> 0 Then
>                         Set prp = fld.CreateProperty("InputMask",
> dbText, strMask)
>                         fld.AllowZeroLength = True
>                         fld.Properties.Append prp
>                     End If

>                 .Fields.Append fld

>                 Set idx = .CreateIndex("idxaltCode")
>                     With idx
>                         .Fields.Append .CreateField("altCode")
>                     End With
>                 .Indexes.Append idx
>                 .Fields.Refresh
>                 .Indexes.Refresh
>         End With

> It does everything I want it to do except set the input mask.  Help
> anyone?

> Richard



Mon, 27 Oct 2003 22:38:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Set Format and Input mask of existing field

2. input mask on text field and split function

3. input mask on text field and split function

4. Programmatically alter database field properties / input mask with VB6

5. Input Masking for phone number fields

6. DAO creating an Autonumber field

7. creating an autonumber field in DAO

8. Creating a ComboBox Field in a TableDef through DAO

9. Unwanted spaces filling up my Access Fields when Creating Database with DAO

10. Creating new field using VB5/DAO 3.5

11. Creating new field using VB5/DAO 3.5

12. bound masked field to date/time field in access not formatting right

 

 
Powered by phpBB® Forum Software