Skip to main content

Example of how to update a field

This does not seem to work on virtual fields, so if you are using this make sure that the field you create is an IDEA field.
Function updateField()
	Dim db As database
	Dim table As table
	Dim field As field
	Dim rs As Object
	Dim rec As Object
	Dim count As Long
	Dim i As Long
	
	Set db = client.OpenDatabase("Book111-Sheet1.IMD")
	Set table = db.TableDef
	Set Field = table.GetField("TEST")
	Set rs = db.RecordSet
	rs.ToFirst
	
	count = db.count 'get the number of records

	field.Protected = FALSE
		For i = 1 To count
			rs.Next
			Set rec = rs.ActiveRecord
			

			rec.SetNumValue "TEST", 1
			rs.SaveRecord rec
		Next i
	field.Protected = TRUE
	
	Set rec = Nothing
	Set rs = Nothing
	Set field = Nothing
	Set table = Nothing
	Set db = Nothing
End Function