TOPIC: Get and set field values with program
#890
Get and set field values with program 3 Years, 3 Months ago
I still don't understand this important part of Suneido working. I'm not a good programmer, actually, but I think that this way either too complicated for me or too briefly explained in User's manual.

Perhaps I have a field (invoice) and want to:
a) read the field data
b) set the field datd with the program (on button click)

What do I do in VBA (say, in MS Accees)?

I add the code to the form's module like this:

Code:


Sub Button_click
me.invoice="12345"
End Sub



This is the simpliest way (or I could write like this: me.controls("invoice").value="12345"

And to read the value I simply write:

Code:


Dim strVar

strVar=me.invoice



This is the way I would explain how to read and set data in MS Access form. Could you please explain me how to do this in Suneido? Say, I have a field 'invoice' in Access control and event

On_MyButton

and want to read value from field and set a new value, say, ++old_value

I've read the RecordControl page in User's manual but don't understand what to do this the Access and Browse controls

Say:

Code:


Controller
{
Controls:
(Access
title: "Enter Invoices"
invoice
(Vert
(Horz invoice_number Skip customer Skip invoice_main)
Skip
(Button "Test"')
Skip
(Browse
"invoicelines",
columns: (product, qty, price, total_price, invoice)
linkField: invoice,
name: "invoice_main"')
)
)
On_Test()
{
<<- here I want to insert my code
}

}



when I 'wrap' Access in #Record lik this:

Code:


Controls:
#(Record
(Access




and then use .Data.GetField('field_name') or .Data.SetField('field_name', 'field_value') it gives me nothing... though there are no errors. But field don't changes. And more, I think there is some way to set or get data without RecordControl.
 
 
#893
Re:Get and set field values with program 3 Years, 3 Months ago
AccessControl already wraps your controls in a RecordControl (you do not need to add your own). You can get the actual data with .Access.GetData(). Normally this is all you need, but if necessary you can get a reference to the RecordControl with .Access.GetRecordControl().

For example:
Code:


On_Test()
    {
    data = .Access.GetData()
    data.invoice = data.invoice + 1
    }


RecordControl has an observer on the data record and when it changes it automatically updates the control and marks the record as "dirty" (requires saving).

Note: When you move to a different record in AccessControl, the data object changes, so this is one case where you cannot just get a reference to the data in New.

Post edited by: andrew, at: 2007/05/08 00:01
 
 
andrew
 
#894
Re:Get and set field values with program 3 Years, 3 Months ago
Thank you, Andrew! Your support is really amazing!