How to create a table using CREAT TABLE in MS Access

Clive Beaton
Clive Beaton used Ask the Experts™
on
How can I create the following table using the CREATE TABLE method in MS Access.

UsrMsgUID      AutoNumber, Primary key, indexed
UsrMsg             Text 255
HideUsrMsg      Boolean

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
1. Click the Create tab on the Ribbon to display the icons for creation functionality.
2. Click Query Design in the Queries section.
3. Place below code
CREATE TABLE [Your Table Name)
(
UsrMsgUID AUTOINCREMENT PRIMARY KEY,
UsrMsg CHAR(255),
HideUsrMsg Bit
)

Open in new window

4. Save query
5. Open in design mode and execute

Best Regards
Clive BeatonAccess Developer

Author

Commented:
Thanks Mohit.  

I should have been more clear.  I need to run the whole process as a function in VBA as part of an automatic data conversion on client machines.
Okay, are you asking for VBA function to create table?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Clive BeatonAccess Developer

Author

Commented:
Yes, please.
Here you go

Sub CreateTable()
 
     Dim dbs As Database
 
    ' Modify this line to include the path to Your Database Name
    ' on your computer.
    Set dbs = OpenDatabase("C:\Users\mohi\Documents\Database2.accdb")
        
    dbs.Execute "CREATE TABLE Ramlal1 " _
        & "(UsrMsgUID AUTOINCREMENT PRIMARY KEY, " _
        & "UsrMsg CHAR, HideUsrMsg BIT); "
 
    dbs.Close
 
End Sub

Open in new window

Clive BeatonAccess Developer

Author

Commented:
Perfect.  Thank you very much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial