Delete Table If Field Value Matches Criteria (1 Viewer)

josephff

Registered User.
Local time
Today, 09:27
Joined
Oct 25, 2011
Messages
72
This is going to be a little more trivial than the title makes it out to be, but im hoping someone can help..

What i need to to do in essence is this...Look through all tables that have a name beginning with "441-" and if a criteria matches a field in there delete that table, then look through the rest.

Notr sure where to start as im not very proficient with loops

Code:
dim name1 as string
 
For each Table in MsysObjects
     If [Name] = "441-*" then
            name1 = [Name]
 
            nz(dlookup("field", name1))
                  if name1 >= 2 then
                        DoCmd.DeleteObject acTable, name1
                  end if
     end if
 
next
 

josephff

Registered User.
Local time
Today, 09:27
Joined
Oct 25, 2011
Messages
72
well ive started it kind of

i've put all the values into a listbox and then ran a loop through all of them
Code:
Dim strSQL As String
    Dim lst As ListBox
 
    Set lst = Me.ExistingLst
 
    strSQL = "SELECT [Name] FROM MSysObjects WHERE [Type] = 1 And " & _
         "Left$([Name], 4) = '" & Me.BranchTxt.Value & "' and name <> '441-Main' ORDER BY [Name]DESC ;"
 
    lst.RowSourceType = "Table/Query"
    lst.RowSource = strSQL

Code:
Dim intItemsInList As Integer, intCounter As Integer
    Dim lst As ListBox
 
    Set lst = Me![ExistingLst]
    intItemsInList = lst.ListCount
 
    For intCounter = 0 To intItemsInList - 1
      CheckTable1 (lst.ItemData(intCounter))
    Next

then for now the CheckTable1 function just pushes a msgbox to verify im pulling all the data
 

josephff

Registered User.
Local time
Today, 09:27
Joined
Oct 25, 2011
Messages
72
i figured this out...
 

Users who are viewing this thread

Top Bottom