View Full Version : how to delete a table that have a prerequirement


thomashunter
11-22-2004, 08:33 AM
Hello dear all,

I met a problem, when I use macro to delete a query, I want to express that "if the query (or table) exist , then delete it", and the macro should carry on this command without any prompt message box.

I try several ways, but whatever you input to the condition box of a macro, they always ask you to locate the objects at first, they couln't indentify the object if it don't exsit!

thanks in advance. :p

FoFa
11-22-2004, 04:34 PM
Use a function to return say true if the object exist, and put the function call in the conditional section of the macro line for the delete, if you search here you will find a function that checks for tables existing I think.

thomashunter
11-23-2004, 01:23 AM
thank you fofa, I try the isobject() funciton, but it can only identify the controls in the form. Is there any other function could identify is it a table?

Mile-O
11-23-2004, 04:15 AM
Pass your table name to this function. Ensure a DAO reference is enabled.

Public Function IsTable(ByVal TableName As String) As Boolean
On Error GoTo Err_IsTable
Dim tdf As DAO.TableDef
Dim strTemp As String
strTemp = CurrentDb.TableDefs(TableName).Name
IsTable = True
Exit Function
Err_IsTable:
IsTable = False
End Function

thomashunter
11-24-2004, 07:34 AM
Hello SJ McAbney, I just follow your good suggestion, but when I use the macro runcode, and try to run the "IsTable (mytablename)" function, Access couldn't find my table.

I am sure have opened the DAO reference.

Mile-O
11-25-2004, 02:11 AM
And you have used:

RunCode("MyTable")


in your macro

and not:

RunCode(MyTable)

?

You will also have to move the DAO reference above that for ActiveX Data Objects.

thomashunter
11-25-2004, 03:49 AM
I forgot the quotation mark, now it works, thanks for you help SJ !