Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Thanked 0 Times in 0 Posts

    default value in Back End Database (Access 2000)

    Default Value in Back End Database

    I have the following task.I have to create a new field in the Back End database as follows
    name of the field: Orderdate
    Data Type: Date/Time
    Format: ShortDate
    DefaultValue = Date()
    Indexed Yes(DuplicatesOK)

    I have tried to do that but i gave it up,too complicated for me. And besides it doesnt work. Can somebody help me with the creating the new field?
    My code up to now is :
    Dim wsp As DAO.Workspace
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Dim prp As DAO.Property
    Set wsp = DAO.DBEngine.Workspaces(0)
    Set dbs = wsp.OpenDatabase ("C:MyPathMyDatabase.mdb")
    Set tdf = dbs.TableDefs("orders")
    Set fld = tdf.CreateField("orderdate", dbDateTime)
    Set prp = fld.CreateProperty("DefaultValue")
    Set prp = fld.CreateProperty("DefaultValue")
    prp.Type = dbText
    tdf.Fields.Append fld
    prp.Value = "Date()"
    fld.Properties.Append prp
    Set fld = Nothing
    Set tdf = Nothing
    Set dbs = Nothing
    Set wsp = Nothing

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Toronto, Ontario, Canada
    Thanked 0 Times in 0 Posts

    Re: default value in Back End Database (Access 2000)

    You have to append the flied to the tabledef before you can create a property.
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts