Update value of a field

R

Ray Mead

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
 
D

Duane Hookom

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top