condition in Macro

K

Ken Snell

From a post by Dirk Goldgar, ACCESS MVP, dated 20 May 2003 (in
microsoft.public.access newsgroup):

There's no builtin way to do this that I know of. You need a little VBA
function, like this:

'----- start of code -----
Function fncTableExists(TableName As String) As Boolean
If Len(TableName) = 0 Then Err.Raise 5
On Error Resume Next
fncTableExists = IsObject(CurrentDb.TableDefs(TableName))
End Function

'----- end of code -----

You would copy that code, paste it into a standard module, and save the
module. Then you could use it in a macro condition, like this:

Condition: fncTableExists("MyTable")
Action: DeleteObject
ObjectType: Table
ObjectName: MyTable

I'd point out that, as long as you need to use some code anyway, you
might rewrite your macro completely in code. The part that deletes the
table could call the function first:

If fncTableExists("MyTable") Then
DoCmd.DeleteObject acTable, "MyTable"
End If

--
Dirk Goldgar, MS Access MVP


Note: you can find earlier posts by using Google.com to search the
newsgroups. Go to http://www.google.com/ and click on Groups. Good luck!
 

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