Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a table with code, is there a way?

Status
Not open for further replies.
Jul 8, 2002
61
US
I have a button of a form to input a text file into an access table. The button pops up an input box that asks for the name of the file, then imports it using an import specification (not the important part) into a pre-existing table. The code basically works like when you import data manually and you choose to import it to an 'existing table'. The problem is if that existing table does not exist access will create it and import the data into, with the format being incorrect (basically missing fields that I need in the table, but aren't in the text file to import).

To get to the point... In that code that asks the user for the name of the text file to import, I would like to write some code that creates the table (if it doesnt already exist) with all the necessary fields, then imports the data into it. I'm assuming that since you can do practically anything to a table in code, you can create one too, but what is the syntax for creating a table with code? thanks to anyone who can help!
 
Here is one methiod that works. Read about Create Table in the Jet SQL Reference in Access Help.

Dim sqlstmnt As String

sqlstmnt = &quot;Create Table TableName (Col1 <type>, Col2, <type>, ...)&quot;
currentdb.Execute(sqlstmnt) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top