Friday, October 22, 2010

Update All fields in a table on a given condition (VBA)

Given below function is used to update All fields in a table on a given condition.

Sub ListTableFields(TableName As String)

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim fldCurr As DAO.Field

Set dbCurr = CurrentDb()
Set tdfCurr = dbCurr(TableName)

For Each fldCurr In tdfCurr.Fields

DoCmd.SetWarnings False

If fldCurr.Type = 10 Then
DoCmd.RunSQL ("Update " & TableName & " Set " & fldCurr.Name & " =NEw Values Where " & fldCurr.Name & "=Value To be updated ")

End If

Next fldCurr

Set fldCurr = Nothing
Set tdfCurr = Nothing
Set dbCurr = Nothing

End Sub

No comments:

Post a Comment