Solved

Check a Table exists before deleting it

Posted on 2014-10-24
2
157 Views
Last Modified: 2014-10-24
Dear Experts,

Courtesy of EE Access, I have a piece of code which should check to see if an access table exists, if it does then it deletes it.

Unfortunately I keep getting an error - User defined type not defined (it highlights the line ... Dim td As DAO.TableDef)

The code is below, can anybody help?

Private Function UpdateTables_Click()
DoCmd.OpenForm "Refreshing"
DoCmd.SetWarnings False
'Test for tables
Dim td As DAO.TableDef
On Error Resume Next
Set td = CurrentDb.TableDefs("Dbo_AppointmentsView")
If Err = 0 Then DoCmd.DeleteObject acTable, "Dbo_AppointmentsView"
Else
Err.Clear
End If
Set td = CurrentDb.TableDefs("dbo_AssignmentFeeAllocationsView")
If Err = 0 Then DoCmd.DeleteObject acTable, "dbo_AssignmentFeeAllocationsView"
Else
Err.Clear
End If

'next table etc etc 

Open in new window

0
Comment
Question by:correlate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 40401817
In the VBA editor window, go to tools, references.

Scroll down the list and find "Microsoft DAO 3.60 Object Library"  and check it.

Click OK and you will be set.

Jim.
0
 

Author Closing Comment

by:correlate
ID: 40401843
Perfect thank you very much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question