Results 1 to 8 of 8
  1. #1
    Cojack is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    7

    Alter table Yes/No field

    Hi Everybody,

    How do I add an Yes/No field into my Access via Alter statement.

    ALTER TABLE TABLE1
    ADD CHECKED YesNo;

    Above sql add a collum to my table with Yes/No type.


    However databaseview of the table show me 0 and -1 but i would like to have the checkboxes.

    Regards,

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if you want to change it to checkbox format, go t design view and change it.

    If you want to chagne in VBA code, you can try using tabledef to add fields (I've never tried, so I cann't tell you how).

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    weekend,

    I don't know if this is thread hijacking or not yet because it's so old, but I thought I would drop a line and give the syntax for adding fields to a table via code:
    Code:
    dim db as database
    set db = currentdb   
    Dim tbldef As DAO.TableDef
    Set tbldef = db.TableDefs(tablename)
    
       With tbldef
          .Fields.Append .CreateField(newfieldName, fieldtype (example - 'dbText'))
       End With
    
    db.TableDefs.Refresh
    
    Set tbldef = Nothing

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Quote Originally Posted by ajetrumpet View Post
    weekend,

    I don't know if this is thread hijacking or not yet because it's so old,
    The date is 10/19/2010

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by weekend00 View Post
    The date is 10/19/2010
    it was 'kind of' a joke, sir. At any rate though, now you have the code you need. woohoo!

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Can we set the Display Control to checkBox instead of default TextBox? like:

    field.displayControl = acCheckBox

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    after 100 times trying, I modify your code as:
    Code:
    dim db as database
    set db = currentdb   
    Dim tbldef As DAO.TableDef
    dim fld as dao.field
    Set tbldef = db.TableDefs(tablename)
       With tbldef
           fld=.CreateField(newfieldName, "yesno") 
           fld.properties("DisplayControl")=accheckBox
          .Fields.Append fld
       End With
     
    db.TableDefs.Refresh
     
    Set tbldef = Nothing

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Another way.

    after add column, change the display control type:

    docmd.runsql "ALTER TABLE TABLE1 ADD CHECKED YesNo;"
    currentdb.TableDefs("table1").Fields("checked").pr operties("DisplayControl")=acCheckBox

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

Similar Threads

  1. Selecting a corresponding table field based on text field.
    By michaeljohnh in forum Programming
    Replies: 5
    Last Post: 10-08-2010, 10:33 AM
  2. Update 1 field from a table to another table
    By Mere_Male_1960 in forum Queries
    Replies: 1
    Last Post: 09-28-2010, 09:40 PM
  3. Replies: 0
    Last Post: 08-10-2010, 01:29 PM
  4. Alter Views/Queries in MDB from C# application.
    By avadhutkhavare in forum Access
    Replies: 0
    Last Post: 11-03-2009, 04:07 AM
  5. Replies: 4
    Last Post: 09-03-2009, 02:01 PM

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