Results 1 to 5 of 5
  1. #1
    Juanna_v is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    18

    add new column and set default value

    Hi all. Once more I need your precious help.

    I used the code below to add a new column to an existing table that works ok but I need some more things.



    A. I want to add 3 columns instead of 1 and
    B. I want the fields to be TEXT fields with their default values set to something let's say "No Further Action"

    Can you please help me?

    The code I used :

    Private Sub Command1_Click()
    Dim strField As String
    Dim curDatabase As Object
    Dim tblTest As Object
    Dim fldNew As Object


    Set curDatabase = CurrentDb
    Set tblTest = curDatabase.TableDefs("tblTEST")

    strField = "TestColumn2"

    Set fldNew = tblTest.CreateField(strField, dbLong)
    tblTest.Fields.Append fldNew

    End Sub


    Thank you in advance

  2. #2
    Juanna_v is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    18
    Never mind this. I found it out. Thanks anyway.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Care to share your solution with others that read this Forum?

  4. #4
    Juanna_v is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    18
    Sure. I used the code above adding some lines.
    Since I'm not an expert I hope what u read below is not anything very strange , but it worked for me.

    Private Sub Command3_Click()

    Dim strField As String

    Dim curDatabase As Object
    Dim tblTest As Object
    Dim fldNew As Object
    Dim fldNew1 As Object
    Dim fldNew2 As Object
    Dim fldNew3 As Object

    Set curDatabase = CurrentDb
    Set tblTest = curDatabase.TableDefs("tblDbtCrdt")


    strField = "Notes"
    strField1 = "Action"
    strField2 = "AlertType"
    strField3 = "GrTypo"

    Set fldNew = tblTest.CreateField(strField, dbText)
    Set fldNew1 = tblTest.CreateField(strField1, dbText)
    Set fldNew2 = tblTest.CreateField(strField2, dbText)
    Set fldNew3 = tblTest.CreateField(strField3, dbText)
    tblTest.Fields.Append fldNew
    fldNew.DefaultValue = "NoComments"

    tblTest.Fields.Append fldNew1
    fldNew1.DefaultValue = "NoAction"

    tblTest.Fields.Append fldNew2
    fldNew2.DefaultValue = "DbtCrdt"

    tblTest.Fields.Append fldNew3
    fldNew3.DefaultValue = "SameDay"


    End Sub

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thanks! Others will appreciate your solution. Go ahead and use the Thread Tools and mark this thread as Solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2012, 11:54 AM
  2. Export to .pdf with default name
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 12-23-2010, 10:27 AM
  3. Replies: 7
    Last Post: 04-27-2010, 02:47 PM
  4. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  5. inserting values in column based another column
    By wasim_sono in forum Database Design
    Replies: 1
    Last Post: 06-27-2006, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums