Using a form to add/subtract values

Creating and using forms
Post Reply
zxcv411
Posts: 1
Joined: Mon Apr 28, 2008 3:52 am

Using a form to add/subtract values

Post by zxcv411 »

I'm trying make a form that uses two text fields, "customerId" and "itemAmt", and two buttons, "add" and "subtract", and when you click on the 'Add' button it increases the "itemAmt" by one for that item for "customerId". Both "customerId" and the values of "itemAmt" are in the same table, and the "itemAmt" values are all numbers.

I have tried everything that I can think of, and have looked in multiple places for any sort help, and I have found nothing that will fix this.
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Using a form to add/subtract values

Post by DrewJensen »

Actually I put up a post on this a long time ago...in a galaxy far way...LOL...but darned if I can now however..so.

You could hard code this for your particular form ( meaning this particular column in this specific table ) or you can do this by creating a generic type of macro that you could use. ( this is only good for integers...but you could expand it to handle other data types also )

Code: Select all

Sub incColumn( aCol as variant , bPlusMinus as Boolean )
'
' incColumn will update the data stored in the buffer
' for the rowset for the column passed as aCol
'
'

dim Val as integer
if bPlusMinus then
  Val = 1
else
  Val = -1
endif

' updateInt and getInt are both part of
' API for an XColumn object
'
  acol.updateInt( aCol.getint + Val )

End Sub
Then you have to call the proceudre with the correct column. Assign this procedure then to the "When initializing" event on the Add button.

Code: Select all

sub onAdd_1_ButtonClick( oEv as object )
'
' events such as mouse clicks always call
' a procedure or function with a paramter of
' type eventObject
' the eventObject will have a property Source
' which here is the graphic button
' A deffernce between the source object
' we get in an event handler call
' and from XDataForm.getControl( )
' is that in getControl the return is a
' control's model
'
' Here we have the instance of the control
' so to get to the parent Dataform object
' we need to go via the model

dim oDataForm as object
oDataForm = oEv.Source.Model.Parent

' then call our incColumn procedure
' the idea here is that the procedure actually
' assigned to the button event just sets up
' the paremeters for a general function
'
' incColumn will update our actual table field

incColumn( oDataForm.Columns( oDataForm.FindColumn( "itemAmt" )), True)

end sub
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Post Reply