Counter in VBA

  • Thread starter Thread starter Sydney
  • Start date Start date
S

Sydney

Guest
I would like to setup a count when a user enters a number into a textbox. The user may ammend this number by entering a +/- value into another textbox which should update the first entry. I would like the user to click a command button which will decrement the count by one each time the command button is clicked. When zero is reached a messagebox should appear displaying count complete validate.

Can anyone help?

Many thanks
 
Hi "Sydney"
Providing I understand yr requirements - this should work

You have to add a Combo or List box (both will work) to add the operator "+" or "-"
between yr two text boxes. (I cant see a way round this because "+" or "-" cannot be converted to numbers)
So:
You end up with: a Combo/List via Wizard or manually - with properties:
RowSource "+";"-"
Columncount 1
Defaultvalue "+"
(make default - or make entry required - ie if no entry - msgbox?- ie after update_ txtTwo - then exit until entered )

This will work with following code under yr form: - this new - Combo/List is here called "ListOp"

Use Code as following:-

txtOne = yr 1st number textbox
txtTwo = yr 2nd number textbox-(value to be altered in txtOne)
ListOp = Value of operater in code (entered by user)

Add to yr - txtTwo_AfterUpdate event
_______
Dim x As Integer
Dim y As Integer
x = CInt(Me![txtOne])
y = CInt(Me![txtTwo])

Select Case Me![ListOp]
Case Is = "+"
x = x + y
Case Is = "-"
If x > 0 Then ' this prevents minus values being entered
x = x - y
End If
End Select
Me![txtOne] = "" & x
'if txtOne has controlsource then add
Me![txtOne].Refresh

________
Add to yr - Command button_OnClick event
Dim x As Integer
x = CInt(Me![txtOne])
If x > 0 Then
x = x - 1
Me![txtOne] = "" & x
If Me![txtOne] = "0" Then
MsgBox "Now zero"
End If
ElseIf x = 0 Then
MsgBox "Still zero!"
End If
'if txtOne has controlsource then add
Me![txtOne].Refresh


Any Probs -Pse post

[This message has been edited by Ron Bell (edited 08-11-2000).]

[This message has been edited by Ron Bell (edited 08-11-2000).]
 

Users who are viewing this thread

Back
Top Bottom