|
-
Aug 21st, 2000, 02:04 PM
#1
Thread Starter
Hyperactive Member
I asked this question a long time ago and I didn't understand what people told me. How do you delete a table. The code I am using to creat a table is.
Code:
Dim rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\mydb.mdb", False, False, ";pwd=password")
Set tdfTable = dbsData.CreateTableDef(Text1.Text)
With tdfTable
.Fields.Append .CreateField("amount", dbCurrency)
End With
dbsData.TableDefs.Append tdfTable
rcdTable.Close
dbsData.Close
Thank you so very much!!!!
-
Aug 21st, 2000, 02:14 PM
#2
Monday Morning Lunatic
I usually use the DELETE TABLE SQL statement.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 02:22 PM
#3
Thread Starter
Hyperactive Member
I have no idea how to use sql I was told by someone else I could create tables this way.
Code:
Set dbsData = CreateDatabase(path, dbLangGeneral & ";pwd=password")
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path1, False, False, ";pwd=password")
dbsData.Execute "CREATE TABLE Usernames (ID AUTOINCREMENT, Name TEXT, Password TEXT)"
He also said there was a way to delete them this way but he never showed me how. Is this a SQL statement? THanks!!!
-
Aug 21st, 2000, 02:26 PM
#4
Monday Morning Lunatic
Yes. For example:
Code:
SELECT * FROM People WHERE LastName="Jones"
pass that as the parameter to an OpenRecordset method to get the result.
Use Database.Execute("DELETE TABLE MyTable") to delete a table, I think.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 02:56 PM
#5
Thread Starter
Hyperactive Member
Well this doesn't work. Anybody know why or have any suggestions? Thanks!!
Code:
Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
dbsData.Execute ("DELETE TABLE Currency.mdb")
-
Aug 21st, 2000, 02:59 PM
#6
Frenzied Member
Drop Table tablename
is standard SQL for removing a table.
-
Aug 21st, 2000, 03:46 PM
#7
Monday Morning Lunatic
I thought that the DROP statement was for deleting a whole database?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 04:36 PM
#8
JHausmann is correct. To delete an entire table using SQL, its:
db.Execute "DROP TABLE TableName"
(The DELETE statement in SQL deletes records from a table, but the table itself remains intact. DROP TABLE wipes the whole table.)
For Access databases, you can also delete a table using the following DAO code (with DAO, the method IS "Delete"):
db.TableDefs.Delete "TableName"
"It's cold gin time again ..."
Check out my website here.
-
Aug 21st, 2000, 04:40 PM
#9
Monday Morning Lunatic
I know he's correct, but I was just confirming the details in my mind. It's just that I get confused occasionally...
My usual DB, mySQL, uses DROP DATABASE and DELETE TABLE a lot, so I'll check the details. Thanks for pointing that out, though.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 04:42 PM
#10
Frenzied Member
Originally posted by parksie
I thought that the DROP statement was for deleting a whole database?
Depends on what you want to drop ... 
Drop table
Drop index
Drop database
-
Aug 21st, 2000, 06:08 PM
#11
Monday Morning Lunatic
Aha. I see now .
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 07:22 PM
#12
At the risk of beating a dead horse, I believe you guys when you say that other DBMS's may support DROP DATABASE, but as far as I know, MS-Jet SQL for Access DB's supports only DROP TABLE and DROP INDEX (not DROP DATABASE).
"It's cold gin time again ..."
Check out my website here.
-
Aug 21st, 2000, 07:25 PM
#13
Frenzied Member
Jet's hardly standard SQL.
-
Aug 21st, 2000, 08:54 PM
#14
Agreed. But since Pitbull seemed to be doing the Access/Jet/DAO thing, that's perspective I took on this question.
"It's cold gin time again ..."
Check out my website here.
-
Aug 21st, 2000, 11:28 PM
#15
Thread Starter
Hyperactive Member
Well I can't get the sql statement to work. This is exacltly what i have:
Code:
Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
dbsData.Execute "DROP TABLE Integer"
I get an error that says:
Run-time error '3295':
Syntax error in DROP TABLE or DROP INDEX.
I have also tried doing this:
Code:
Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
dbsData.Execute "Delete TABLE Integer"
I get an error that says:
Run-time error '3075':
Sytax error (missing operator) in query expression 'Table Integer'
and I have also tried this:
Code:
Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
dbsData.Execute "delete * from Integer"
I get an error that reads:
Run-time error '3131':
Sytax error in FROM clause.
and not one of them works. Why is that? Thanks!!
-
Aug 22nd, 2000, 12:32 AM
#16
Lively Member
Integer ?
I think that the problem is the name of the table. Integer might be a reserved word. I am not sure and I do not have Access to test it on.
Yesterday, all my troubles seemed so far away...
Help, I need somebody, Help...
Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.
-
Aug 22nd, 2000, 12:34 AM
#17
New Member
I'm using Access97 VB - adding to the code you started off with I have inserted a delete command (as already mentioned by BruceG above)
Code:
Sub CreateAndDeleteTable()
Dim rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = CurrentDb
Set tdfTable = dbsData.CreateTableDef("Text1")
With tdfTable
.Fields.Append .CreateField("amount", dbCurrency)
End With
dbsData.TableDefs.Append tdfTable
MsgBox "Table Created"
dbsData.TableDefs.Delete (tdfTable.Name)
MsgBox "Table Deleted"
End Sub
All without SQL - does this help?
Alex
-
Aug 22nd, 2000, 11:57 AM
#18
Frenzied Member
Originally posted by PITBULLCJR
Well I can't get the sql statement to work. This is exacltly what i have:
Code:
Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
dbsData.Execute "DROP TABLE Integer"
I get an error that says:
Run-time error '3295':
Syntax error in DROP TABLE or DROP INDEX.
I have also tried doing this:
Code:
Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
dbsData.Execute "Delete TABLE Integer"
I get an error that says:
Run-time error '3075':
Sytax error (missing operator) in query expression 'Table Integer'
and I have also tried this:
Code:
Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
dbsData.Execute "delete * from Integer"
I get an error that reads:
Run-time error '3131':
Sytax error in FROM clause.
and not one of them works. Why is that? Thanks!!
I believe AKA is right and that "Integer" is a reserverd word. However, if it let you build the table with that name, you should be able to access the table by wrapping it in brackets, ie, [Integer] in your queries.
-
Aug 22nd, 2000, 02:22 PM
#19
Thread Starter
Hyperactive Member
Thank you guys but if I use what Alexn gave me it works fine and dandy. It even deletes the integer table. I have many tables and I just so happened to use that one for an example. Thank You so very much for your time!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|