[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.
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
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.