Results 1 to 3 of 3

Thread: [RESOLVED] Dynamically create autonumber / boolean field in Access 2003

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    7

    Resolved [RESOLVED] Dynamically create autonumber / boolean field in Access 2003

    I'm using Access 2003 with a VB 2005 front end.

    I have this code written to dynamically create a table in an access database:

    Code:
                        DBCommand.CommandText = "CREATE TABLE Item(" & _
                        "ItemID Varchar(255) NOT NULL UNIQUE," & _
                        "ItemName Varchar(255) NOT NULL," & _
                        "ItemDesc Varchar(255) NOT NULL," & _
                        "ItemCat Varchar(255) NOT NULL," & _
                        "ItemType Varchar(255) NOT NULL," & _
                        "ItemQty Integer NOT NULL," & _
                        "ItemWarn Integer NOT NULL," & _
                        "ItemVendor Varchar(255) NOT NULL," & _
                        "ItemVisible Varchar(255) DEFAULT 'Yes' NOT NULL," & _
                        "ItemUnit Varchar(255) NOT NULL," & _
                        "ItemOrdered Varchar(255) DEFAULT 'No' NOT NULL," & _
                        "PRIMARY KEY (ItemID));"
    
                         DBCommand.ExecuteNonQuery()
    The above code works.

    However, for obvious reasons, I wouldn't want a field such as "ItemVisible" or "ItemOrdered" to be a string, I'd prefer to use a yes/no field. They're only varchar at the moment because I can't make this command work any other way.

    So, this brings me to my question: What does the command need to be in order to dynamically create a yes/no (boolean) field in an Access DB?

    Also, what does the command have to be to dynamically create an autonumber field in the database?

    I've looked quite a bit on the internet, and I can't find any examples of this. And my book from class only has some basic examples using text/number fields. Any help would be appreciated. Thanks.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Dynamically create autonumber / boolean field in Access 2003

    For Boolean use Bit, and for AutoNumber I think you need use Integer with a constraint:
    http://office.microsoft.com/en-gb/ac...CH010410151033

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    7

    Re: Dynamically create autonumber / boolean field in Access 2003

    Ah yes, Bit. Lol, I've been sitting here trying to think of all the different synonyms for Boolean, that one alluded me.

    Also, I finally found that you can use "Counter" as a way to specify Autonumber.

    Thank you very much for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width