Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This was the ONLY place that I could find information that I could use to resolve the problem. So thanks once again to member TomSark and the SQL forum!..."

Geography

Where in the world do Tek-Tips members come from?
cimoli (TechnicalUser)
21 Jul 12 13:39
I would like to know how to make a Command Button automatically delete 2 tables. Extra credit if I can have an "Are You Sure? kind of deal inside the command button too.

I have a month routine where by I import a table from another Office of ours. The table imports as tblCustInfo1 into the HDQ Access 2010 file. I have a routine that makes a new table off of this one. It is called TomCustInfo. When my work is done, I want to automatically delete tblCustInfo1 and TomCustInfo.

I tried something from a 2003 tek-tips article. but I get an error.

The following is on the ON CLICK line.

Private Sub cmd8910_Click()

Dim Db As DAO.Database
Dim tbl As DAO.TableDef
Set Db = CurrentDb()

For Each tbl In Db.TableDefs

If tbl.Name = "TomCustInfo" Then
DoCmd.DeleteObject acTable, "TomCustInfo"

Else
End If
Next

For Each tbl In Db.TableDefs

If tbl.Name = "tblCustInfo1" Then
DoCmd.DeleteObject acTable, "TblCustInfo1"

Else
End If
Next

End Sub
PHV (MIS)
21 Jul 12 13:50
cimoli (TechnicalUser)
21 Jul 12 15:26
Oops. When trying to get 2 tables erased inside 1 command button, the error says:

"Run time error '2387'. You can't delete the table tblCustInfo1; it is participating in 1 or more relationships."

The following is noted in Yellow:
DoCmd.DeleteObject acTable, "tblCustInfo1"


By the way, if take out the following towards the end,
the buton works fine and deletes the table TomCustInfo. Although i wish i had a message that says,something like, you are about to delete TomCustInfo, yes or no.

(i took this part out and the command button erases tomcustinfo)

For Each tbl In Db.TableDefs
If tbl.Name = "tblCustInfo1" Then
DoCmd.DeleteObject acTable, "TblCustInfo1"
Else
End If
Next

tblCustInfo1 is not part of my relationships. My plain tblCustInfo is part of the relationships.
The table with the "1" at the end came from an import like i said.

thanks for checking this. If we can fix, this will allow me to ensure that i clean up my unwanted tables at the end.
Helpful Member!  Andrzejek (Programmer)
23 Jul 12 8:16

For an Extra credit smile

CODE

If vbYes = MsgBox("Are you sure?", _
    vbYesNo + vbQuestion + vbDefaultButton2, _
    "Delete Tables?") Then

    'Your Delete code goes here....
    
End If 

But what will happen when User says: No? Your tables will not be deleted.

Have fun.

---- Andy

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close