drop Microsoft Access XP table with Visual Basic

G

Guest

Dear developer,
I have an error message when I try to delete or drop Microsoft Access XP
table with ADOX in Visual Basic 6. I use the ADOX.Catalog and ADOX.table to
create and delete or drop table within Visual Basic program.
If anybody knows how to solve the problem, please give me the solution.
I would like to thank you for your attention and response.

Best regard,

Sanad
 
L

Leon Mayne [MVP]

delete said:
Dear developer,
I have an error message when I try to delete or drop Microsoft Access
XP table with ADOX in Visual Basic 6. I use the ADOX.Catalog and
ADOX.table to create and delete or drop table within Visual Basic
program.
If anybody knows how to solve the problem, please give me the
solution.
I would like to thank you for your attention and response.

Hello,
What's the error message you're getting?
 
M

Miha Markic [MVP C#]

Hi,

This is a wrong newsgroup for vb 6 (this is *dotnet*).
Anyway, what error do you get?
Maybe the table in question is referenced by another table and thus can't be
dropped?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"delete table with Visual Basic 6" <delete table with Visual Basic
(e-mail address removed)> wrote in message
news:[email protected]...
 
G

Guest

My error message is "Run time error '3265': Item cannot be found in the
collectioin corresponding to the requested name or ordinal". But when I check
my database, the table to be deleted is exist. And also the name is excactly
the same with the value of the variable DelCodeNumber.
Here is the code:
Dim catStok As New ADOX.Catalog
Dim tblStok As New ADOX.Table

catStok.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\dbStok.mdb;"
tblStok.Name = DelCodeNumber
catStok.Tables.Delete tblStok
Set catStok.ActiveConnection = Nothing
Set catStok = Nothing

Thank you very much for your attention

Best Regard,

Sanad
 
L

Leon Mayne [MVP]

delete said:
Dim catStok As New ADOX.Catalog
Dim tblStok As New ADOX.Table

catStok.ActiveConnection =
"Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\dbStok.mdb;"
tblStok.Name = DelCodeNumber
catStok.Tables.Delete tblStok
Set catStok.ActiveConnection = Nothing
Set catStok = Nothing

Have you stepped through to check the value of DelCodeNumber to make sure
it's correct?
 
G

Guest

I have stepped through to check the value of DelCodeNumber, and the value I
use is "1", because indeed the table name I create in the database is a kind
of code number, like "1" , "12" , "25", "314", etc.
So the value of variable DelCodeNumber is "1", not "1.tbl". I had use the
"1.tbl" but the result is the same.

catStok.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\dbStok.mdb;"
tblStok.Name = NoKodeDel + ".tbl"

catStok.Tables.Delete tblStok --> Here the program stop running

Set catStok.ActiveConnection = Nothing
Set catStok = Nothing

I use Visual Basic 6 within Visual Studio 6 Enterprise Edition, and Ms
Access XP.
If you have a better or another way just to delete / drop Ms Access XP table
with Visual Basic 6, let me know. Or may be have I to use Ms Access 97 and
use DAO ?

Thank you very much for your attention.
 
G

Guest

Finally, I get the answer!!!
I get the answer in the Visual Basic-database.ado section in this newsgroup
date 4/1/2005 by Brendan Reynolds.
Thank you again for Mr.Brendan Reynolds.

The answer is:

"If the function returns True, call Catalog.Tables.Delete YOURTABLENAME to
delete the table."

My mistake is

Dim tblStok As New ADOX.Table

tblStok.Name = DelCodeNumber
Catalog.Tables.Delete tblStok --> error

Catalog.Tables.Delete DelCodeNumber --> correct

By the way, I appreciate Mr. Leon Mayne for the VERY FAST attention and
answer. And also thank you for Mr.Miha Markic for the advice and forgiveness.

All right, have a nice work. Your work means a lot for us.

Best regard,

Sanad
 
P

Paul Clement

¤ Dear developer,
¤ I have an error message when I try to delete or drop Microsoft Access XP
¤ table with ADOX in Visual Basic 6. I use the ADOX.Catalog and ADOX.table to
¤ create and delete or drop table within Visual Basic program.
¤ If anybody knows how to solve the problem, please give me the solution.
¤ I would like to thank you for your attention and response.
¤

BTW, you can also use Access SQL DDL:

DROP TABLE TableName


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top