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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check whether a table exists before running a macro? 2

Status
Not open for further replies.

CHTHOMAS

Programmer
Jun 16, 1999
106
AE
Hi,<br>
Could any one suggest me how to check whether a table exists before running a macro? ie if the table exists don't run the macro else run the macro.<br>
Regards,<br>
Charley
 
Well you could create a VBA function.<br>
like this:<br>
---------------------------------<br>
Public Function sample()<br>
On Error GoTo Err_Sample<br>
DoCmd.OpenTable &quot;Tablename&quot;<br>
'if the the table dose not exist then it will return an Error 7874<br>
Exit_Sample:<br>
Exit Function<br>
<br>
Err_Sample:<br>
Select Case Err.Number<br>
Case 7874<br>
' Table not found<br>
DoCmd.RunMacro &quot;MacroName&quot;<br>
Case Else<br>
MsgBox &quot;Error # &quot; & Err.Number & &quot; &quot; & Err.DESCRIPTION, vbInformation, &quot;In sub xxxxxxxxxx&quot;<br>
Resume Exit_Sample<br>
End Select<br>
<br>
End Function<br>
------------------------------------- <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top