Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro condition clause help? 1

Status
Not open for further replies.

larryww

Programmer
Mar 6, 2002
193
0
0
US
When you open up the condition column in (A2000) macro design, you can put a UDF (or other function that returns True or False) whether to execute a macro statement(s). I've seen examples with IsNull().

How would I condition based on whether a table exists, such as IfExists(tblFoo)? IsObject didn't seem to do the trick.

The objective is to prevent the warning when I do a DeleteObject Action on a table that doesn't exist. Amazingly enough, SetWarnings to No does not stop this error message. [evil]
 
Your IfExists() function is actually the best way to do it. You just need to create the function.

Create a standard module and enter this function into it:
Code:
    Public Sub IfExists(TableName As String) As Boolean
        Dim tdf As DAO.TableDef

        On Error Resume Next
        Set tdf = CurrentDb.TableDefs(TableName)
        IfExists = (Err = 0)
        Set tdf = Nothing
    End Sub
In your macro condition column, put:
IfExists("tblFoo") Rick Sprague
 
Thanks, Rick. I hoped to avoid a UDF, but since it looks like I must, that's a pretty tight and clean yet fully explicit explanation (wtg! May all my questions be answered thusly LOL).

I tried various things in the condition column:

[currentdb].[tabledefs]("tblFoo").[RecordCount]>=0
[currentdb].[querydefs]("query1").[myCount]>=0
(Query1 produced a field Mycount from tblFoo).

I also tried variations of IsObject() and IsError() but the irritating part was the impotence of SetWarnings to No. [mad]

Still, very nice and accurate answer.
 
BTW, oops - looks like that function is wearing a Sub coat [sadeyes]
 
[blush]You're right--but you knew to change it to Function, right?

BTW, the reason the Set Warnings doesn't work is that the message is an error, not a warning. Errors occur when a requested action simply can't be done. Warnings occur when it can be done, but has potentially harmful consequences. So deleting an object that isn't there is an error, while deleting one that is there is a warning. Rick Sprague
 
Solution achieved:
DCount(&quot;*&quot;,&quot;MSysObjects&quot;,&quot;type = 1 and name = 'tblFoo'&quot;)<>0

Works right there in the condition column
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top