Results 1 to 2 of 2
  1. #1
    bcofie is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2011
    Posts
    31

    Access 2007--Alter table using vb.

    Prive Sub AddColumn_Click()


    CurrentDB.Execute("ALTER TABLE ADD COLUMN NewField Text(30);")

    This above works but I want to replace NewField with Me.TextBox1.Value so that user can type in a name in textbox on form and add as a field.
    Also will like to replace Text(30) with Me.Cbo.SelectedValue.

    I know letting users add fields is not great idea but until I manage to talk them out of it...........

    Thanks!!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Concatenate the variables:

    CurrentDB.Execute "ALTER TABLE ADD COLUMN [" & Me.TextBox1 & "] Text(" & Me.Cbo & ");"

    If this is required to maintain database, sounds like data structure is wrong. How does this impact design of forms and reports?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-29-2011, 09:39 AM
  2. Replies: 10
    Last Post: 08-30-2011, 04:49 PM
  3. Access 2007 junction table issue
    By dwilson in forum Access
    Replies: 11
    Last Post: 08-07-2011, 03:39 PM
  4. Summary table query Access 2007
    By DesCall in forum Access
    Replies: 4
    Last Post: 05-05-2011, 02:38 AM
  5. Alter table Yes/No field
    By Cojack in forum Queries
    Replies: 7
    Last Post: 10-27-2010, 11:31 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