Source language: Translate to:

get field value of a selected record in a grid

Questions about our Advanced Database plug-in

Moderator: Neosoft Support

get field value of a selected record in a grid

Postby Daved » Fri Nov 15, 2013 5:48 pm

I have a non editable and I can select records in the grid and the related records show in another object.
so the relationships are correct.
On add new record I need to extract the common field from record 1 and update a value in record 2 .
Any of the get field value actions return a comma separated list of all records in the grid.
Howdo I get the selected record?
Also why doesn't the dbrelationship auto populate such fields on record create?

Dave
Daved
 
Posts: 19
Joined: Mon Nov 11, 2013 3:37 pm

Re: get field value of a selected record in a grid

Postby Gaev » Fri Nov 15, 2013 6:56 pm

Daved:
Howdo I get the selected record?
From the Help file ... Creating Database Enabled Publications >>> Working with Data ...
When creating or opening a database table, NeoBookDBPro will automatically create NeoBook variables for each field it finds. Because NeoBookDBPro allows you to open up an unlimited number of databases and tables at the same time, and many tables use similar field names, NeoBookDBPro combines the database ID and the table's name with the field name to create a unique variable. For example, let's open a Microsoft Access database called "AddressBook":

dbpOpenAccessDatabase "MyDB" "c:\my files\AddressBook.mdb" ""

Next, let's open a table inside AddressBook called "Clients":

dbpOpenTable "MyDB" "Clients" ""

The Clients table contains the following fields:

FirstName
LastName
Street
City
State
Zip
Telephone

After opening the table, NeoBookDBPro would automatically create the following NeoBook variables:

[MyDB.Clients.FirstName]
[MyDB.Clients.LastName]
[MyDB.Clients.Street]
[MyDB.Clients.City]
[MyDB.Clients.State]
[MyDB.Clients.Zip]
[MyDB.Clients.Telephone]

Each variable is a combination of the Database ID (MyDB), a period (.), the Table Name (Clients), a period (.) and the field name. Since NeoBookDBPro allows you to open multiple databases and tables at the same time, this method makes it unlikely that any two databases will have conflicting field names.

Only one record in the table is considered active at a time. This active, or current record, is the source of the field variables' data. If another record becomes active, the field variables are automatically updated with the contents of the new record. This linkage works both ways, so any changes to the field variables in NeoBook are also automatically reflected in the database. This powerful link between the database and NeoBook means that you don't need to be concerned with the complexities of reading and writing data.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: get field value of a selected record in a grid

Postby Daved » Fri Nov 15, 2013 8:30 pm

Thanks for you response,
I understand all of that but when I execute a setvar from table1.field to table2.fielld or to a variable the result is 298,290 which happen to be the grids records key fields. I can't seem to get the selected record's value of the field.
Daved
 
Posts: 19
Joined: Mon Nov 11, 2013 3:37 pm

Re: get field value of a selected record in a grid

Postby Gaev » Sat Nov 16, 2013 5:22 am

Daved:

Please post the relevant lines of script so we can understand your problem.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: get field value of a selected record in a grid

Postby Daved » Sat Nov 16, 2013 12:05 pm

:Block_entry
dbpOpenDatabase "treecount" "C:\Users\Dave-HP\Documents\Longtion Application Builder Projects\longtiondb\trees1.mdb"
dbpOpenTable "treecount" "Entity" ""
dbpOpenTable "treecount" "orchards" ""
dbpOpenTable "treecount" "Blocks" ""
dbpShowGrid "treecount" "orchards" "Rectangle3"
dbpSetGridProperties "treecount" "orchards" "ConfirmDelete=No;RowSelect=Yes;ShowNavigationBar=No"
dbpDefineRelationship "treecount" "orchards" "ID" "Blocks" "orchard_ID" ""
DefineVar "[entityid]" "Integer" "" "Global" ""
dbpFieldToVar "treecount" "Entity" "ID" "[entityid]" "Delimiter=,;SkipBlanks=Yes;NoDuplicates=Yes;DelimiterInContext=Leave"
DefineVar "[orchardId]" "Undefined" "" "Global" ""
Return

"on Add Button:
dbpAddRecord "treecount" "orchards"
SetVar "[treecount.orchards.ID]" "[orchardId]"
MessageBox "Return value" "[orchardId]" "" ""
Returns "289,290"
Which are the ID of all the records in the file.
My question is how do I get the selected record and it's field values from the parent grid in order to update the related fields of the added record?
The parent record field is an auto increment key field to an integer field of the child record.
Daved
 
Posts: 19
Joined: Mon Nov 11, 2013 3:37 pm

Re: get field value of a selected record in a grid

Postby Gaev » Sat Nov 16, 2013 5:33 pm

Daved:

1) This code ...
Code: Select all
dbpFieldToVar "treecount" "Entity" "ID" "[entityid]" "Delimiter=,;SkipBlanks=Yes;NoDuplicates=Yes;DelimiterInContext=Leave"
... will (according to the Help file) ...
Copy the contents of a single field from each record to a variable. Items will be separated by the specified delimiter. If a search query is active, only records matching the query will be copied.
... but in the line immediately before, you have ...
Code: Select all
DefineVar "[entityid]" "Integer" "" "Global" ""
... i.e. you deine [entityid] as an "Integer" ... that does not seem right ... try "String".

2) In this code ...
Code: Select all
dbpAddRecord "treecount" "orchards"
SetVar "[treecount.orchards.ID]" "[orchardId]"
MessageBox "Return value" "[orchardId]" "" ""
... if you want to save the value of the (auto generated) ID field (from the current record in the "orchards" Table) in a variable called [orchardid], the parameters in the SetVar command should be the other way around i.e. ...
Code: Select all
SetVar "[orchardId]" "[treecount.orchards.ID]"
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: get field value of a selected record in a grid

Postby Daved » Sat Nov 16, 2013 5:43 pm

Thanks,
I have it working.
Daved
 
Posts: 19
Joined: Mon Nov 11, 2013 3:37 pm


Return to NeoBookDBPro

Who is online

Users browsing this forum: No registered users and 1 guest