Page 1 of 1

Using a form to add/subtract values

Posted: Mon Apr 28, 2008 4:06 am
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.

Re: Using a form to add/subtract values

Posted: Fri May 02, 2008 3:40 am
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