Group:  Microsoft Access ยป microsoft.public.access.macros
Thread: Need if statement in macro

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Need if statement in macro
ChrisP 10.07.2006 14:06:02
I need to write a macro that if a table already exists in the database it
will skip importing the table and if the table doesn't exist the macro will
import it. Any help is appreciated. Thanks.
Re: Need if statement in macro
Steve Schapel <schapel[ at ]mvps.org.ns> 11.07.2006 11:08:58
Chris,

This can not be done with an If statement (and in any case, If
statements are not related to macros). In fact, it can't directly be
done in a macro at all. You would need to use VBA to write a
user-defined function in a standard module, to check the existence of
the table, and then use this function in the Condition of your macro.
Such a UDF might look something like this...

Public Function TableExists(TableName As String) As Boolean
Dim i As Integer
For i = 0 To CurrentDb.TableDefs.Count - 1
If CurrentDb.TableDefs(i).Name = TableName Then
TableExists = True
Exit For
End If
Next i
End Function

Then, in your macro Condituion, you could put the equivalent of
TableExists("YourTable")

--
Steve Schapel, Microsoft Access MVP

ChrisP wrote:
[Quoted Text]
> I need to write a macro that if a table already exists in the database it
> will skip importing the table and if the table doesn't exist the macro will
> import it. Any help is appreciated. Thanks.

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net