Question

Asked on 2003-08-12 at 03:12:53ID: 27002691

    Set the DefaultValue of a table field using AccessVB

    by: AndyB_Member125

    Rating8.8Very Good

    Hi,
    I'm struggling with DEFAULTVALUE again when producing tables with VBcode, not by hand in DesignView.

    What i have is a NEW table that i'm using for AuditTrail with a field named TimeStamp that has (in DesignView) the
    defaultvalue of Format(Now(), "dd\,mmm\,yyyy\,hh:nn:ss")

    Monthly i need to email the tables from the application by using a simple transportable database which i attach to an email.

    With a bit of code (the audit table part-of below) i build the database, tables and export the relevant data into the tables.

    Set dbs = wspdef.CreateDatabase(New_Database, dbLangGeneral)
    Set audit_tblDef = dbs.CreateTableDef("AuditTable")
    With audit_tblDef
            Set idx = .CreateIndex("AuditIndex")
            With idx
                .Fields.Append .CreateField("TransactionID", dbLong)
            End With
            .Indexes.Append idx
            Set fld = .CreateField("TransactionID", dbLong)
            fld.Attributes = fld.Attributes + dbAutoIncrField
            .Fields.Append fld

    * My problem is - I can't get what's in the brackets to be defaultvalue, it puts the date/time (i'd like to swear here!) whereas i want "Format()" etc.

            Set fld = .CreateField("TimeStamp", dbText, 25)
            fld.DefaultValue = (Format(Now(), "dd\,mmm\,yyyy\,hh:nn:ss"))
            .Fields.Append fld

    ***************************
            .Fields.Append .CreateField("UserName", dbText, 50)
            .Fields.Append .CreateField("WorkstationName", dbText, 50)
            .Fields.Append .CreateField("UserInput", dbText, 50)
            dbs.TableDefs.Append audit_tblDef
    End With

    I know before you say it that i can do the format() bit when passing data to the table at the .addnew stage in my AuditTrail Function.
    BUT i've had problems setting up DEFAULTVALUE and FORMAT parts by VBcode before and given up and really i'd like to know how to do it.

    Last time i was trying by code to make the tick-boxes appear in the fields with the Format part but failed.
    At best i managed true/false yes/no but i couldn't produce that blank tickbox that appears in designview when you select "Yes/No"

    Any help would be appreciated thanx.
    AndyB.

    Related Solutions

    Solution

    Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

    About this Solution

    View This Solution - Start Your 30 Day Free Trial
    Zone
    general
    Tags
    accessvb database defaultvalue
    Participating Experts
    1
    Solution Grade
    A

    Replies

     by: MrRobin

    Posted on 2003-08-12 at 04:36:55ID: 35590894

    All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

     by: MrRobin

    Posted on 2003-08-12 at 04:39:02ID: 35590895

    All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

     by: AndyB_Member

    Posted on 2003-08-12 at 04:48:44ID: 35590896

    All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

     by: MrRobin

    Posted on 2003-08-12 at 04:59:10ID: 35590897

    All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

    Log In

    Forgot your password?Sign up

    Top Experts

    1. jimpen

      3,600

      0 points yesterday

      Profile
    2. boag2000

      2,000

      0 points yesterday

      Profile

    BrowseAre you an Expert?