Question : VBA to delete records with a certain value in all tables

I need to modify this code to, instead of dropping tables that start with "raw", I would like to delete all records with a
[fldSeries] (field Name) with a value of [forms]![frmMain]![txtSeries].  

All table names starting with "raw" have the field name of [fldSeries].  Thanks for any suggestions!


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Public Sub DropTables()

Dim td As dao.TableDef, db As dao.Database
Set db = CurrentDb

For Each td In db.TableDefs
    If Left(td.Name, 3) = "raw" Then
        db.Execute "drop table [" & td.Name & "]"
    End If
Next

End Sub

Answer : VBA to delete records with a certain value in all tables

what else?

Public Sub DeleteRecords()

Dim td As dao.TableDef, db As dao.Database, rs as dao.recordset
Set db = CurrentDb

For Each td In db.TableDefs
    If Left(td.Name, 3) = "raw" Then
         if dcount("*",td.name,"[fldSeries]='" & [forms]![frmMain]![txtSeries] &"'")>0 then        
        db.Execute "delete *  from [" & td.Name & "] where [fldSeries]='" & [forms]![frmMain]![txtSeries] &"'"
        end if
    End If
Next

End Sub
Random Solutions  
 
programming4us programming4us