Run Command on Button click based on the number in Textbox

djossh

Registered User.
Local time
Tomorrow, 01:53
Joined
Oct 19, 2011
Messages
89
Hi, I want my button to fire/Run the command below based on the number in my unbound textbox field (txtboxnumber)

the scenario will be... to input the number in my txtbox ex. "5" ....then when I click on the button (ComButton) it will run the code below 5 times...

Private Sub ComButton_Click()
Me.FieldName = Nz(Me.FieldName, 0) + 1
End Sub
 
If it is literally that code in your click event, why not just add the textbox number to the field?
Code:
Me.FieldName = Nz(Me.FieldName, 0) + Val(Nz(Me.txtBoxNumber,0))
If you need the loop, then try this
Code:
Private Sub ComButton_Click()
Dim i As Integer
For i = 1 to Val(Me.txtBoxNumber)
  Me.FieldName = Nz(Me.FieldName, 0) + 1
Loop
End Sub
 
If it is literally that code in your click event, why not just add the textbox number to the field?
Code:
Me.FieldName = Nz(Me.FieldName, 0) + Val(Nz(Me.txtBoxNumber,0))
If you need the loop, then try this
Code:
Private Sub ComButton_Click()
Dim i As Integer
For i = 1 to Val(Me.txtBoxNumber)
  Me.FieldName = Nz(Me.FieldName, 0) + 1
Loop
End Sub


Thanks for the reply.. but Im having a "Loop without Do" error... sorry im a newbie to access and VBA...Thanks again..
 
Sorry - more haste, less speed! I didn't test the code (self evidently!) - I started with a 'Do While' loop, changed my mind to a 'For' loop, then didn't change the loop termination statement.

Just change the 'Loop' statement to 'Next', giving
Code:
Private Sub ComButton_Click()
Dim i As Integer
For i = 1 to Val(Me.txtBoxNumber)
  Me.FieldName = Nz(Me.FieldName, 0) + 1
Next
End Sub
 
Sorry - more haste, less speed! I didn't test the code (self evidently!) - I started with a 'Do While' loop, changed my mind to a 'For' loop, then didn't change the loop termination statement.

Just change the 'Loop' statement to 'Next', giving
Code:
Private Sub ComButton_Click()
Dim i As Integer
For i = 1 to Val(Me.txtBoxNumber)
  Me.FieldName = Nz(Me.FieldName, 0) + 1
Next
End Sub


THANK YOU SO MUCH!! I really appreciate your help.... Thanks again..
 

Users who are viewing this thread

Back
Top Bottom