
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!