RecordSet.SaveRecord

3 posts / 0 new
Last post
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57
RecordSet.SaveRecord

Just a bit of an update to the information in the language browser.  The language browser shows you how to perform this on one row but not on an entire database.  Here is an updated example with a loop to update all the records.

Sub Main

    ' Open the database.
    Set db = Client.OpenDatabase("Sample-Detailed Sales.IMD")
    
    ' Create the task.
    Set NewField = db.TableManagement
    
    ' Obtain a reference to the table.
    Set ThisTable = db.TableDef
    
    ' Create a new field.
    Set MyField = ThisTable.NewField
    
    ' Configure the new field.
    MyField.Name = "MyCharField"
    MyField.Description = "A Sample Field"
    MyField.Type = WI_EDIT_CHAR
    MyField.Length = 25
    MyField.Equation = " """" "
    
    ' Add the field.
    NewField.AppendField MyField
    NewField.PerformTask
    
    ' Obtain the RecordSet from the database.
    Set rs = db.RecordSet
    
    ' Obtain the first record from the RecordSet.
    rs.ToFirst
    count = rs.Count
    
    For i = 1 To count
        Set rec = rs.ActiveRecord
        rs.next
        rec.SetCharValue "MyCharField", "A Value"
        rs.SaveRecord rec
    Next i
    
    db.Close
    
    ' Clear the memory.
    
    Set db = Nothing    
    Set ThisTable = Nothing
    Set MyField = Nothing
    Set rs = Nothing
    Set rec = Nothing

End Sub

Jiyajijp
Offline
Joined: 12/08/2016 - 06:34

 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Jiyajijp, here is the list. Also the different type of fields need different info, such as character field needs the length while a numeric field needs the number of decimals. Probably the easiest way to do this is just open a file, go into the Field Manipulation and append the type of field that you want. Then open the history and you will see the code that you need to create that type of field.

Good luck
Brian

Virtual Character - WI_VIRT_CHAR

Virtual Date - WI_VIRT_DATE

Virtual Numeric - WI_VIRT_NUM

Virtual Time - WI_VIRT_TIME

Boolean - WI_BOOL

Multistate - WI_MULTISTATE

Editable Character - WI_EDIT_CHAR

Editable Date - WI_EDIT_DATE

Editable Numeric - WI_EDIT_NUM

Editable Time - WI_EDIT_TIME

Date Field - WI_DATE_FIELD

Character Field - WI_CHAR_FIELD

Numeric Field - WI_NUM_FIELD

Time Field - WI_TIME_FIELD