Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Current date in a table field

Discussion in 'Information Technology' started by msanewbee, Jul 28, 2006.

  1. msanewbee

    msanewbee
    Expand Collapse
    Guest

    Is there a way to have the current date automatically put in a table field
    whenever a new record is created?
     
  2. Loading...


  3. xRoachx

    xRoachx
    Expand Collapse
    Guest

    Hi -- In design view, add the following to the default value for the date
    field:
    Date()



    "msanewbee" wrote:

    > Is there a way to have the current date automatically put in a table field
    > whenever a new record is created?
     
  4. msanewbee

    msanewbee
    Expand Collapse
    Guest

    That works perfect. Thanks!! :)

    "xRoachx" wrote:

    > Hi -- In design view, add the following to the default value for the date
    > field:
    > Date()
    >
    >
    >
    > "msanewbee" wrote:
    >
    > > Is there a way to have the current date automatically put in a table field
    > > whenever a new record is created?
     
  5. Jamie Collins

    Jamie Collins
    Expand Collapse
    Guest

    msanewbee wrote:
    > Is there a way to have the current date automatically put in a table field
    > whenever a new record is created?


    Use either NOW() or DATE() as the column's default value e.g.

    Sub effective_date()
    Kill "C:\DropMe.mdb"
    Dim cat
    Set cat = CreateObject("ADOX.Catalog")
    With cat
    .Create _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\DropMe.mdb"
    With .ActiveConnection

    ' Create test table
    .Execute _
    "CREATE TABLE Test4 (key_col INTEGER NOT" & _
    " NULL UNIQUE, effective_date DATETIME DEFAULT" & _
    " NOW() NOT NULL); "

    ' Create test row (default gets applied)
    .Execute _
    "INSERT INTO Test4 (key_col) VALUES (1);"

    ' Show results
    Dim rs
    Set rs = .Execute( _
    "SELECT key_col, effective_date" & _
    " FROM Test4;")
    MsgBox rs.GetString
    rs.Close
    End With
    Set .ActiveConnection = Nothing
    End With
    End Sub

    Jamie.

    --
     

Share This Page