Results 1 to 8 of 8
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    DAO ALTER TABLE syntax error


    Not having much success with a DAO ALTER TABLE syntax. Both of the sample tries pictured below fail because of syntax. What am I missing?
    Click image for larger version. 

Name:	000.jpg 
Views:	15 
Size:	62.3 KB 
ID:	37853

  2. #2
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Try DoCmd.RunSQL "ALTER TABLE.......

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    You need ALTER COLUMN and SET
    If its a boolean field
    Code:
    CurrentDB.Execute "ALTER TABLE Families ALTER COLUMN FamilyDonOnly SET Default=False"
    Or for a text field
    Code:
    CurrentDB.Execute "ALTER TABLE Families ALTER COLUMN FamilyDonOnly SET Default='No'"
    I recommend using https://www.w3schools.com/sql
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Hi Colin,
    Neither your suggestion or Thompty's was met with success: (Both failed because of syntax error) And yes, "FamilyDonOnly" is YES/NO.
    Click image for larger version. 

Name:	001.jpg 
Views:	14 
Size:	55.7 KB 
ID:	37855

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Using DoCmd.RunSQL is less efficient than CurrentDB.Execute

    I've double checked several sites and the = should have been omitted
    However I'm also getting the syntax error.
    Some reference sites say you need to ADD / DROP CONSTRAINT first but that's not worked either
    I'm sure I've done this before but at the moment I can't solve it
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    The answer just came to me.
    This IS correct
    Code:
    CurrentDB.Execute "ALTER TABLE Families ALTER COLUMN FamilyDonOnly SET DEFAULT False"
    or you can do that as a DDL query in query SQL view
    but the SET DEFAULT statement is only supported if you use ANSI 92 syntax.

    To do that, tick the box below

    Click image for larger version. 

Name:	Capture.PNG 
Views:	9 
Size:	21.4 KB 
ID:	37863

    However you will get a warning that enabling this will have knock-on effects on the rest of your database.
    A couple of years ago, I ticked that & forgot about it then started getting issues.
    Eventually when I realised the link I unticked it again

    Personally I would just set the default(s) manually and leave well alone but its up to you
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Colin,
    The issue isn't a show stopper. I have backend DB's in the wild that needed the default updated IF I wanted to tweak some code in the frontend. My app includes a general module that maintains compatibility between app versions and corresponding backend versions. I would need to add the "ALTER TABLE" statement to that module for the next app version release. I'm going to scrap the idea completely but grateful to you for your persistence in finding a solution.
    Thanks,
    Bill

    (PS) I made a copy of my app's frontend, ticked the box, closed and reopened and ran your statement but it still fails with a syntax error. Please don't spend anymore time on this.

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    You can still use ALTER TABLE with ALTER COLUMN without the ANSI92 setting but not the SET DEFAULT part.
    One solution might be to set it temporarily to ANSI92 for the upgrade, then use code to reset back to 'normal' once changes are completed.
    Or have a separate utility that runs the BE updates and isn't used for any other purpose.
    Or use a VB Script...there's always a way
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. ALTER TABLE query syntax error
    By Sck in forum Queries
    Replies: 3
    Last Post: 09-07-2018, 01:01 PM
  2. Alter Table Statement
    By jo15765 in forum Modules
    Replies: 5
    Last Post: 03-09-2017, 05:05 PM
  3. Replies: 1
    Last Post: 08-06-2012, 07:15 AM
  4. Alter Table syntax error
    By markjkubicki in forum Programming
    Replies: 1
    Last Post: 02-06-2012, 05:43 PM
  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