Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2003
    Posts
    3

    Unanswered: Defaut datetime value when creating table

    hi,

    i'm trying to create a table with a datetime field which default value is now().
    No matter what i try, i get a syntax error..., can anybody help please ?


    CREATE TABLE MyTable (
    Mydate DATETIME DEFAULT now()
    )

  2. #2
    Join Date
    Jan 2003
    Location
    Midwest
    Posts
    138
    instead of Now() try using Date()

  3. #3
    Join Date
    Mar 2003
    Posts
    3
    Originally posted by Memnoch1207
    instead of Now() try using Date()
    thx, but no...still have that syntax error in sql statement

  4. #4
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Hey

    The only way I know how to do something like that is with vb. Like this:

    Dim db As DAO.Database
    Dim table1 As New DAO.TableDef
    Dim fld As New DAO.Field

    Set db = CurrentDb
    Set table1 = db.CreateTableDef
    Set fld = table1.CreateField("field", dbDate)

    table1.Name = "MyTable"
    table1.Fields.Append fld
    fld.DefaultValue = "Date()"

    db.TableDefs.Append table1

    hope this helps............................................. ..

    Later, Kal

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Zed (canadian, eh?), your syntax is fine, it is access that is screwed up

    according to Intermediate Microsoft Jet SQL for Access 2000,

    Note The DEFAULT statement can be executed only through the Jet OLE DB provider and ADO. It will return an error message if used through the Access SQL View user interface.

    rudy

  6. #6
    Join Date
    Mar 2003
    Posts
    3
    thx guys...

Posting Permissions

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