Results 1 to 3 of 3
  1. #1
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67

    Deleting Tables With Wildcard?

    Trying to get the below code to iterate through all the tables in my db and delete any tables that begin with "str_arch_chk".

    The problem is that it looks as if the wildcard "*" is being treated literally. So, not sure what to use for the wildcard? Or if I need to write the code differently?

    Any suggestions are appreciated..thanks!


    Function fcn_tbl_delete_all_str_arch_chk_tbls()
    Dim str_arch_chk As String
    Dim t As TableDef
    Dim db As DAO.Database


    Set db = CurrentDb
    str_arch_chk = "str_arch_chk_tbl_temp_2"
    Dim str_arch_chk_var As String
    str_arch_chk_var = Left(str_arch_chk, 12) & "*"

    For Each t In db.TableDefs
    If fcn_tbl_exists(str_arch_chk_var) Then
    DoCmd.DeleteObject acTable, str_arch_chk
    End If
    Next

    End Function
    Function fcn_tbl_exists(str_tbl_name)
    'checks to see if a table exists..
    Dim d As Database
    Dim tdf As TableDef
    On Error Resume Next
    Set d = CurrentDb
    Set tdf = d.TableDefs(str_tbl_name)

    If Err = 3265 Then
    fcn_tbl_exists = False
    Else
    fcn_tbl_exists = True
    End If
    Err = 0
    End Function

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    You may be better off using the "Like" operator.....

    Code:
    Function funDeleteImportErrors()
        Dim obj As AccessObject, dbs As Object, strTableName As String
        
        Set dbs = Application.CurrentData
        For Each obj In dbs.AllTables
            If obj.Name Like "*$_ImportErrors*" Then
                strTableName = obj.Name
                DoCmd.DeleteObject acTable, strTableName
            End If
        Next obj
    End Function

  3. #3
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67
    Cool, this works perfect, thanks!

    Quote Originally Posted by jgelpi16 View Post
    You may be better off using the "Like" operator.....

    Code:
    Function funDeleteImportErrors()
    Dim obj As AccessObject, dbs As Object, strTableName As String
     
    Set dbs = Application.CurrentData
    For Each obj In dbs.AllTables
    If obj.Name Like "*$_ImportErrors*" Then
    strTableName = obj.Name
    DoCmd.DeleteObject acTable, strTableName
    End If
    Next obj
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. If OR statement (maybe a wildcard?)
    By Lorlai in forum Queries
    Replies: 5
    Last Post: 07-27-2011, 10:21 AM
  2. replace a character with a wildcard
    By neeedhelp in forum Programming
    Replies: 2
    Last Post: 04-11-2011, 05:02 PM
  3. SQL wildcard character excluding
    By sandlucky in forum Access
    Replies: 2
    Last Post: 03-28-2011, 03:33 AM
  4. Replies: 11
    Last Post: 12-14-2010, 01:25 PM
  5. Parameter Query & Wildcard
    By Rick West in forum Queries
    Replies: 8
    Last Post: 12-29-2009, 10:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums