Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    77

    Unanswered: Run macro if table exists

    I'm looking for a way to run a macro if a table exists, if not run a different macro. Something like:

    If TableExists "tblONE"
    DoCmd.RunMacro ("macONE")
    Else
    DoCmd.RunMacro ("macTWO")
    End If

    I see some of these mentioned here but I've been less than successful at getting them to work. Any help would be appreciated.

    Thanks,
    SKK

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Just create a function that looks like this:

    Code:
    Function TableExists(strName As String) As Boolean
      Dim tdef As TableDef
      For Each tdef In CurrentDb.TableDefs
        If tdef.Name = strName Then
          TableExists = True
        End If
      Next
    End Function
    Then call it with:

    Code:
    If TableExists ("tblONE") then
      DoCmd.RunMacro ("macONE")
    Else
      DoCmd.RunMacro ("macTWO")
    End If
    I'm pretty sure there's another way, but I haven't had enough coffee yet to remember it.
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2004
    Posts
    77
    GotIt - thank you.

    SKK

  4. #4
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •