Source language: Translate to:

Add calculated field to table?

Questions about our Advanced Database plug-in

Moderator: Neosoft Support

Add calculated field to table?

Postby smokinbanger » Sat May 19, 2012 8:39 pm

Is it possible to add a "calculated" field to an Access Db?

Example:
I have a table with the fields Quantity and Unit Price and Total
When I adjust either Quantity and Unit Price field the Total field should update automatically without using dbpSaveEdits

Is this possible?
smokinbanger
 
Posts: 198
Joined: Mon Jan 16, 2012 9:53 am
Location: United States

Postby Wrangler » Sun May 20, 2012 8:57 am

Look at using an "onchange" subroutine. Add the name of the sub at the end of the create or opentable actions.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby smokinbanger » Sun May 20, 2012 12:22 pm

Wrangler wrote:Look at using an "onchange" subroutine. Add the name of the sub at the end of the create or opentable actions.
That works to an extent but the problem is the onchange isn't executed when you select the next FIELD in the grid view, only when you select the next record (or save).
smokinbanger
 
Posts: 198
Joined: Mon Jan 16, 2012 9:53 am
Location: United States

Postby Wrangler » Sun May 20, 2012 12:31 pm

What is wrong with using dbpsaveedits?

You can also consider using text entry boxes to edit the fields and use dbpsaveedits in it's action. It should automatically update in the grid as you type.

In the onchange subroutine, do your math to get the total and use dbpsaveedits. The field should update in the grid when you select another field.

I've always found editing data in the grid is a bit quirky. I prefer to use textentry boxes located either on the screen, or pop up in a custom window.

Also be sure you add the name of the sub to your dbpopentable action.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby smokinbanger » Sun May 20, 2012 1:22 pm

Wrangler wrote:In the onchange subroutine, do your math to get the total and use dbpsaveedits. The field should update in the grid when you select another field.

When editing in the grid view, tabbing through the FIELDS doesn't exec the onchange until you reach the end and tab into the next (or new) record. Unless maybe I'm just doing something else wrong.

Wrangler wrote:...I've always found editing data in the grid is a bit quirky. I prefer to use textentry boxes located either on the screen, or pop up in a custom window...
I agree but this particular application needs to be able to edit in the grid
smokinbanger
 
Posts: 198
Joined: Mon Jan 16, 2012 9:53 am
Location: United States

Postby Wrangler » Sun May 20, 2012 2:26 pm

It won't update itself until you navigate to a new record. That is the design. Unless you use dbpsaveedits. Changing the content of a field in the grid will fire the onchange subroutine when you move to another field. If your subroutine contains the math to update the total and dbpsaveedits, changing the data in any of the fields will update the total and save the edits.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby smokinbanger » Sun May 20, 2012 2:41 pm

Wrangler wrote:Changing the content of a field in the grid will fire the onchange subroutine when you move to another field.
For some reason I can't get it to work. It works fine when moving to another record but not by moving to another field. Any idea why?
smokinbanger
 
Posts: 198
Joined: Mon Jan 16, 2012 9:53 am
Location: United States

Postby Neosoft Support » Mon May 21, 2012 10:33 am

The OnChange subroutine only executes when you change records. There is no way to detect when navigating between fields. My suggestion would be to add an update button that calls dbpSaveEdits which will trigger the OnChange sub. You can assign it a shortcut key and tell users to press that key to update the calculations.

You might also try using MS Access to add a calculated field to your table. I'm not sure if it will carry over to DBPro or not, but worth a try.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby smokinbanger » Mon May 21, 2012 3:04 pm

Neosoft Support wrote:You might also try using MS Access to add a calculated field to your table. I'm not sure if it will carry over to DBPro or not, but worth a try.
I don't know if MS Access can do that. At least I couldn't figure out how to so I'm open to tips and suggestions there.
smokinbanger
 
Posts: 198
Joined: Mon Jan 16, 2012 9:53 am
Location: United States

Postby Neosoft Support » Tue May 22, 2012 10:47 am

I'm not a MS Access user, so maybe it doesn't do calculated fields.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to NeoBookDBPro

Who is online

Users browsing this forum: No registered users and 1 guest