Solved Get existing value, Add value from another textbox for total (1 Viewer)

Chief

Registered User.
Local time
Today, 10:50
Joined
Feb 22, 2012
Messages
156
Hello,
Nearly Xmas, hope everyone enjoys their holidays. :)
I have a continuous form where I would like to enter a value in one box (not bound), click button and add that to the value of another textbox (Bound).

1639955739973.png


This is what I have so far, not sure how to indicated where the value/Total is to update in the bound field.
Code:
' Check TxtAddMins is > 0
' Take figure (mins) from TxtAddMins and add to TxtActualMins, TxtActualMins updates with total
' Clear TxtAddMins
Private Sub BtnAddMins_Click()
Dim txtmessage As String
Dim addmins As Integer
txtmessage = ""

    If Nz(Me.TxtAddMins) = 0 Then
        txtmessage = MsgBox("Please enter assembly minutes to Add to Actual Minutes." & vbCrLf & txtmessage)
        Me.TxtAddMins.BackColor = vbRed
        Me.TxtAddMins.ForeColor = vbWhite
        Me.TxtAddMins.SetFocus
    Else
        Me.TxtAddMins.BackColor = vbWhite
        Me.TxtAddMins.ForeColor = vbBlack
            addmins = Int(TxtActualMins) + Int(TxtAddMins)
            Me.TxtAddMins.Value = 0
    End If
End Sub

Thanks
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:50
Joined
Feb 19, 2002
Messages
43,213
The problem with using an unbound control is that as soon as you type something in it, that value will show up in all rows. You might want to use an input box to get a value instead. It is a little awkward but at least it doesn't confuse the users by having the value show on every row.
 

oleronesoftwares

Passionate Learner
Local time
Today, 10:50
Joined
Sep 22, 2014
Messages
1,159
Me.boundtext=Me.unboundtext

add the code to the click event of the command button
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:50
Joined
Feb 19, 2002
Messages
43,213
@Chief - I'm not sure what the "like" means. If it means you are going to take my suggestion, saying so would be more helpful to the people who find this thread later:) If it is just a participation trophy, thanks, I guess.
 

Chief

Registered User.
Local time
Today, 10:50
Joined
Feb 22, 2012
Messages
156
@Chief - I'm not sure what the "like" means. If it means you are going to take my suggestion, saying so would be more helpful to the people who find this thread later:) If it is just a participation trophy, thanks, I guess.
Hey mate,
Just acknowledging, that’s all.
Now I am working on suggestions 😁
I always put up the results and mark as solved.
Stand by 👍🏽
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:50
Joined
Feb 19, 2002
Messages
43,213
Acknowledgements aren't required but we do appreciate knowing the ultimate result.
 

Chief

Registered User.
Local time
Today, 10:50
Joined
Feb 22, 2012
Messages
156
The problem with using an unbound control is that as soon as you type something in it, that value will show up in all rows. You might want to use an input box to get a value instead. It is a little awkward but at least it doesn't confuse the users by having the value show on every row.
Hello,
I have been playing around with inputbox.
I am not sure how to add the figure to the bound box.

Code:
' Check TxtAddMins is > 0
' Take figure (mins) from TxtAddMins and add to TxtActualMins, TxtActualMins updates with total
' Clear TxtAddMins
Private Sub BtnAddMins_Click()
Dim txtmessage As String
Dim addmins As Integer
txtmessage = ""

'    If Nz(Me.TxtAddMins) = 0 Then
'        txtmessage = MsgBox("Please enter assembly minutes to Add to Actual Minutes." & vbCrLf & txtmessage)
'        Me.TxtAddMins.BackColor = vbRed
'        Me.TxtAddMins.ForeColor = vbWhite
'        Me.TxtAddMins.SetFocus
'    Else
'        Me.TxtAddMins.BackColor = vbWhite
'        Me.TxtAddMins.ForeColor = vbBlack
        txtmessage = InputBox("How Many Minutes are you adding?", "Add Minutes", "0", , , , addmins = Int(TxtActualMins) + Int(TxtAddMins))
'            Me.TxtAddMins.Value = 0
'    End If
End Sub

Thank you
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:50
Joined
Feb 19, 2002
Messages
43,213
You do the math outside of the inputbox. prompt for the value. Then use the returned value - after validating it to increment the bound control.

Code:
addmins = Nz(InputBox(...), 0)

If addmins > 0 Then
    Me.txtmins = Me.txtmins + addmins
Else
    Msgbox "No minutes were added.  Please try again.",vbOKOnly
    Exit Sub
End If

I used the Nz() function to avoid a problem with a null result. Otherwise you would have to define addmins as a variant and check for null.
Fill in the details for InputBox(......)
 

Chief

Registered User.
Local time
Today, 10:50
Joined
Feb 22, 2012
Messages
156
You do the math outside of the inputbox. prompt for the value. Then use the returned value - after validating it to increment the bound control.

Code:
addmins = Nz(InputBox(...), 0)

If addmins > 0 Then
    Me.txtmins = Me.txtmins + addmins
Else
    Msgbox "No minutes were added.  Please try again.",vbOKOnly
    Exit Sub
End If

I used the Nz() function to avoid a problem with a null result. Otherwise you would have to define addmins as a variant and check for null.
Fill in the details for InputBox(......)
Thank you so much!

Code:
' Check TxtAddMins is > 0
' Take figure (mins) from TxtAddMins and add to TxtActualMins, TxtActualMins updates with total
Private Sub BtnAddMins_Click()
Dim addmins As Integer

    addmins = Nz(InputBox("How Many Minutes are you adding?", "Add Minutes", 0))

    If addmins > 0 Then
        Me.TxtActualMins = Me.TxtActualMins + addmins
    Else
        MsgBox "No minutes were added.  Please try again.", vbOKOnly
        Exit Sub
    End If
End Sub

:)
 

Users who are viewing this thread

Top Bottom