Update value of a field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a function that creates a new field FileName, can I update that new
field value with the TName? Below is the function code:

Function AddFileName(TName As Variant, fldFileName As String) As Integer
Dim dB As Database, TDef As TableDef, fld As Field

' Get the current database.
Set dB = CurrentDb()
' Open the tabledef to which the counter field will be added.
Set TDef = dB.TableDefs(TName)

' Create a new FileName field

Set fld = TDef.CreateField(fldFileName, dbText)

On Error Resume Next

' Append the new field to the tabledef.
TDef.Fields.Append fld

' Check to see if an error occurred.
If Err Then
AddFileName = False
Else
AddFileName = True
End If

dB.Close

End Function
 
After adding the field to the table, you should be able to use something
like:
dB.Execute "Update [" & TDef.Name & "] SET [" & fldFileName & "] = """ &
TName & """", dbFailOnError
 
Back
Top