create a botton wich increase a value in a textbox

laghetto

Registered User.
Local time
Today, 07:57
Joined
Aug 20, 2011
Messages
27
Hi!
i need your precious help.

i'm using access2003.

i have a textbox with a calculated value in a form.
i'd like to create one botton who incrase of 1 unit that value (in the same box if it is possible)
and one that decrase of one unit.

for example the value in my box is "5", i press the botton "+1" and value become 6.

i tryed with this code but it doesn't work:
Private Sub add1_Click()
Me.box1 = [box1] + 1

End Sub

there is another way?

thanks in advance
 
laghetto,

I would advise that you read up on some VBA basics. It would help you in your development journey.

What is the name of your textbox? Look in the property sheet for the textbox.
 
the name of my text box is: box1
i also tried with
me.box1 = me.box1 + 1

but it doesn't works.

If (in another texbox) i write:
me.box2 = me.box1 + 1
it works correctly so I think the problem is the overwriting.

box1 is not depending to any table or query

thank you for your help.

(i'm not a VBA user but sometime i need some code)

bye
 
* Are you sure it's a textbox? Box1 doesn't sound like a reasonable name. Box is a control and textbox is also a control.
* What is the name of the button?
 
the button name is "add1"

the textbox is named box1 (and i would increase of 1 unit the value for each click on the button

i attach a little example

than you again
 

Attachments

Your textbox has a calculated Control Source. You can't add to a calculated Control Source like that. See attached.
 

Attachments

sorry but if i try your file the box1 stay void.
if i frite some number in the 2 box on the top for example 4 and 5 the box1 is 45 and not 9 (and nothing happens if i click on the button).

There is some way to solve that problem?

thank you
 
Format your boxes as Number or change the code to look like this:
Code:
=Val(Nz([txtbox1], 0)) + Val(Nz([txtbox2], 0)) + Val(Nz([txtbox3], 0))
But before you do that, are the controls now bound?
 
I solved writing the formula in the preset value of my textbox field. and than with
me.box1 = box1 +1
Can I use Val(NZ(...)) in a query? i have some problems id i think it is a format problem.

thank you anyway
 

Users who are viewing this thread

Back
Top Bottom