Variables & Create Table; What's wrong with my code? 
Author Message
 Variables & Create Table; What's wrong with my code?


Quote:
> I need tp use a variable allowing a user to create a table
> named by them. I have tried the following code:
> -------------------------
> Dim newprod As String
> newprod = text1.Text
> Dim sql As String
> Dim Db1 As Database
> Dim Ws As Workspace
> Set Ws = Workspaces(0)  ' Use the default Workspace.
> Set Db1 = Ws.OpenDatabase("cciparts.MDB")
> Db1.Execute "CREATE TABLE" & newprod & "([Product]TEXT,_
> [Price] TEXT)"
> ------------------------
> I get a "syntax error in create table" error. What am I doing
> wrong?
> TIA

Are you using VB4-16 or VB4-32? I use VB3 with Jet 2.5, the
same version of the database engine used by VB4-16.
What you posted has no space between the [Product] and the TEXT.
There is also no space between TABLE and the value of newprod.
If the user enters a table name with a space, you'll need square
brackets as well. Try this:

Db1.Execute "CREATE TABLE [" & newprod & "] ([Product] TEXT, [Price] TEXT);"

Shouldn't the new table have a primary key at least? You can
add one using the CONSTRAINT clause.

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sat, 29 Aug 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Whats wrong with my create object variable code?

2. Can't create table from code.

3. Variable Table Names in Create Tables/Insert Records

4. What's wrong with global variables?

5. Pivot Table and Code (VBA), returns wrong item

6. Creating Identity Colum when Creating table through Code in VB

7. What's wrong with Unique Table Property

8. What's wrong with this code?

9. What's wrong with this code??

10. What's wrong with this OpenDatabase code?

11. What's wrong with this code?

12. What's wrong with this code

 

 
Powered by phpBB® Forum Software