Deleting a Table

H

howard

Hi there

If anyone's able to help me with my Access crashes each
time I try to delete a Table, programmatically, I'd be
most grateful. The code/s I execute to delete a Table is
as below;

Sub myDeleteTable(strTNAME As String)

Dim strPATH As String

strPATH = "C:\DMP_DataBase\September24\DMP_Roy.mdb"
myCallDeleteTable strPATH, strTNAME

End Sub

Sub myCallDeleteTable(strPATH As String, strTNAME As
String)

Dim catDELETE As ADOX.Catalog

Set catDELETE = New ADOX.Catalog
catDELETE.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & strPATH

catDELETE.Tables.Delete strTNAME

Set catDELETE = Nothing

End Sub

Whenever the code gets to the
line: "catDELETE.Tables.Delete strTNAME", it crashes.
Access 2002 comes up with that dialog box that asks if you
want your database repaired, and if you want to send a
report, about the error, to Microsoft.

Please help!

Thanks
H
 
D

Dan Artuso

Hi,
No need to do all that.
Use SQL to it for you.

strSql = "DROP TABLE Trainees " & strTNAME

then just execute it.
 
H

Howard

Hi Dan

Thanks, very much, for your response. I managed to get
round that problem. However, I wonder if you're aware if
Access2002 has issues with ADOX. Codes, like the one
below, which worked fine, previously, begin to make my
system crash.

catADD.ActiveConnection = CurrentProject.Connection
Set tblADD = catADD.Tables(strTBL_to_UPDATE)

This happens when I get to the line "Set tblADD =
catADD.Tables(strTBL_to_UPDATE)"

Or, it could be that I'm overlooking something fundamental
when I use ADOX, in my code?

Thanks and regards
H
-----Original Message-----
Hi,
No need to do all that.
Use SQL to it for you.

strSql = "DROP TABLE Trainees " & strTNAME

then just execute it.

--
HTH
Dan Artuso, Access MVP


"howard" <[email protected]> wrote in
message news:[email protected]...
 

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